Java 内存问题

我昨天用Jconsole连接到我的JBOSS服务器,看到non-heap(PERM)内存 占有率一直都很高(80-90%)但heap的内存一直很低(10%) 左右然后看class装入总数一直在不停的攀升。系统连续运行8-9小时以后就jboss就死了,看了log文件,没有发现有错误日志。
大家帮我看看是什么问题?
系统是用spring+hibernate的写的


这个问题已经解决了,问题是JAXB,我们把JAXB用在MDB中,每一个message进来都会创建一个一样的jaxbcontext,其实这是不需要的,我们现在改成就创建一次,下一次去内存中获取,这样就减少了class装入量。


Q. Are the JAXB runtime API's thread safe?

A. The JAXB Specification currently does not address the thread safety of any of the runtime classes. In the case of the Sun JAXB RI, the JAXBContext class is thread safe, but the Marshaller, Unmarshaller, and Validator classes are not thread safe.

For example, suppose you have a multi-thread server application that processes incoming XML documents by JAXB. In this case, for the best performance you should have just one instance of JAXBContext in your whole application like this:

class MyServlet extends HttpServlet {
static final JAXBContext context = initContext();

private static JAXBContext initContext() {
return JAXBContext.newInstance("....",MyServlet.class.getClassLoader());
}


And each time you need to unmarshal/marshal/validate a document. Just create a new Unmarshaller/Marshaller/Validator from this context, like this:

public void doGet( HttpServletRequest req, HttpServletResponse ) {
Unmarshaller u = context.createUnmarshaller();
u.unmarshal(...);
}


This is the simplest safe way to use the JAXB RI from multi-threaded applications.

If you really care about the performance, and/or your application is going to read a lot of small documents, then creating Unmarshaller could be relatively an expensive operation. In that case, consider pooling Unmarshaller objects. Different threads may reuse one Unmarshaller instance, as long as you don't use one instance from two threads at the same time.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值