• 不停的实例化对象导致OOM


    使用axis调用webService,系统运行一段时间后,出现了 OOM,还好日志中 记下了错误信息。

    Exception in thread "Thread-1301" java.lang.OutOfMemoryError: Java heap space
    	at org.apache.xerces.dom.DeferredDocumentImpl.createChunk(Unknown Source)
    	at org.apache.xerces.dom.DeferredDocumentImpl.ensureCapacity(Unknown Source)
    	at org.apache.xerces.dom.DeferredDocumentImpl.createNode(Unknown Source)
    	at org.apache.xerces.dom.DeferredDocumentImpl.createDeferredDocument(Unknown Source)
    	at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
    	at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
    	at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    	at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:369)
    	at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:388)
    	at org.apache.axis.configuration.FileProvider.configureEngine(FileProvider.java:179)
    	at org.apache.axis.AxisEngine.init(AxisEngine.java:172)
    	at org.apache.axis.AxisEngine.<init>(AxisEngine.java:156)
    	at org.apache.axis.client.AxisClient.<init>(AxisClient.java:52)
    	at org.apache.axis.client.Service.getAxisClient(Service.java:104)
    	at org.apache.axis.client.Service.<init>(Service.java:113)
    	at catic.hotel.server.webservice.PmsServiceData.<init>(PmsServiceData.java:26)
    	at catic.hotel.server.task.SendCmdTask.<init>(SendCmdTask.java:200)
    	at catic.hotel.server.task.TaskFactory.getTask(TaskFactory.java:155)
    	at catic.hotel.server.server.ReadData.read(ReadData.java:82)
    	at catic.hotel.server.server.ReadData.run(ReadData.java:57)
    

      由于系统会频繁的进入到 SendCmdTask,而我又在此构造方法中不停的new PmsServiceData(),而PmsService的无参构造方法中又new Service(),相当于导致了Service对象不停的被实例化,时间久了,则出现OOM。

    解决方法:

      对PmsServiceData使用单例模式,即:

        private static PmsServiceData pmsServiceData = null;
        
        // 单例
        public static synchronized PmsServiceData getInstance(){
            if(null == pmsServiceData){
                pmsServiceData = new PmsServiceData();
            }
            return pmsServiceData;
        }

    问题解决。

  • 相关阅读:
    Compiler Warning C4150: deletion of pointer to incomplete type 'XXX'; no destructor called
    What happend: Exception throws in the .ctor()?
    FocusScope学习一: Logic Focus与Keyboard Focus
    线性筛prime,强大O(n)
    网络流24题方格取数
    splay(1区间翻转区间最值与区间修改)
    排列组合容斥原理
    错排思路
    splay2(区间修改+内存回收)
    DP_1d1d诗人小G
  • 原文地址:https://www.cnblogs.com/xbq8080/p/6289731.html
Copyright © 2020-2023  润新知