java内存溢出问题,不确定哪里出的问题

项目运行的时候出现了内存溢出情况,复现方式无法确定,大概出现了五六次,每次复现的方式都不一样,下面是我用MAT工具分析的dump文件

图片说明
图片说明

除了hibernate里的那两个对象,其他的1000多万个对象里全是integer类型的对象

这是当时出现的时候产生的异常

2020-01-17 13:32:55  ERROR [DruidDataSource.java:2469] - create connection SQLException, url: jdbc:mysql://localhost:55060/mcs?useUnicode=true&characterEncoding=utf-8, errorCode 0, state 08S01
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3517)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3417)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3860)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:864)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1707)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1217)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2189)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2220)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2015)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:768)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.GeneratedConstructorAccessor118.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:385)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:323)
    at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1513)
    at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1578)
    at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2466)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2969)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3427)
    ... 19 more
2020-01-17 13:33:03  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_preset_rlat failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
    at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.getBytes(MemoryEfficientByteArrayOutputStream.java:65)
    at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:99)
    at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:405)
    at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:384)
    at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:485)
    at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1088)
    at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1072)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
2020-01-17 13:32:59  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:32:59  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:32:55  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:16  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:27  WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null
2020-01-17 13:33:27  ERROR [SqlExceptionHelper.java:144] - wait millis 7401, active 16, maxActive 40, creating 1
2020-01-17 13:33:27  INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
2020-01-17 13:33:33  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:33  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:49  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:49  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:49  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:49  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:49  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:53  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:53  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:33:53  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:02  WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null
2020-01-17 13:34:02  ERROR [SqlExceptionHelper.java:144] - wait millis 5503, active 18, maxActive 40, creating 1
2020-01-17 13:34:02  INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
2020-01-17 13:34:04  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:08  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:12  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:12  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:14  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:14  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:14  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:17  WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null
2020-01-17 13:34:17  ERROR [SqlExceptionHelper.java:144] - wait millis 5485, active 19, maxActive 40, creating 1
2020-01-17 13:34:17  INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [null]; error code [0]; Could not open connection; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
2020-01-17 13:34:17  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:27  INFO [DeviceCache.java:249] - 设备状态及报警维护过程中出现异常
2020-01-17 13:34:35  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:35  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:42  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:42  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:44  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:44  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:34:52  WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null
2020-01-17 13:34:52  ERROR [SqlExceptionHelper.java:144] - wait millis 7301, active 22, maxActive 40, creating 1
2020-01-17 13:34:52  INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
2020-01-17 13:34:53  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:35:05  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_roll_preset failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-17 13:35:18  WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null
2020-01-17 13:35:18  ERROR [SqlExceptionHelper.java:144] - Error
2020-01-17 13:35:50  WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null
2020-01-17 13:35:50  ERROR [SqlExceptionHelper.java:144] - Error
2020-01-17 13:36:13  WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001
2020-01-17 13:36:13  ERROR [SqlExceptionHelper.java:144] - Lock wait timeout exceeded; try restarting transaction
2020-01-17 13:36:13  WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001
2020-01-17 13:36:24  ERROR [SqlExceptionHelper.java:144] - Lock wait timeout exceeded; try restarting transaction
2020-01-17 13:36:13  WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001
2020-01-17 13:37:01  ERROR [SqlExceptionHelper.java:144] - Lock wait timeout exceeded; try restarting transaction
2020-01-17 13:37:43  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-17 13:36:37  WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001
2020-01-17 13:36:33  WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001
2020-01-17 13:36:22  WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001

现在就是无法确定到底哪里导致的内存溢出?

这个是上次出现的异常和代码

2020-01-13 13:21:44  WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001
2020-01-13 13:21:44  ERROR [SqlExceptionHelper.java:144] - Lock wait timeout exceeded; try restarting transaction
2020-01-13 13:23:55  INFO [MQTTProtocolHandler.java:283] - 接收到设备接入协议:{"topic":"info/deviceBaseInfo/BHIP118-S/00:00:01:A6:00:A2","reportTime":"256573751","decodeCapacity":{"totalLevel":2,"totalBlock":36,"totalPixel":16588800},"outputList":[{"status":"start","ratio":"UHD","pixel":"3840*2160","type":"UDP","url":"udp://231.0.100.80:7001"},{"status":"start","ratio":"HD","pixel":"960*540","type":"UDP","url":"udp://231.0.101.80:7001"},{"status":"start","ratio":"SD","pixel":"352*288","type":"UDP","url":"udp://231.0.102.80:7001"},{"status":"stop","ratio":"UHD","pixel":"3840*2160","type":"RTMP","url":"rtmp://192.168.15.80:1935/live/100"},{"status":"stop","ratio":"HD","pixel":"960*540","type":"RTMP","url":"rtmp://192.168.15.124:1935/live/101"},{"status":"stop","ratio":"SD","pixel":"352*288","type":"RTMP","url":"rtmp://192.168.15.80:1935/live/102"}],"baseInfo":{"deviceType":"BHIP118-S","code":"00:00:01:A6:00:A2","version":"v1.0.0.11","ip":"192.168.16.80"},"online":true}
2020-01-13 13:23:59  INFO [DeviceCache.java:127] - 接收到新增/更新设备信息:00:00:01:A6:00:A2 :BaseInfo [type=0,name=BHIP118-S,ip=192.168.16.80,port=0,code=00:00:01:A6:00:A2,groupCode=null,groupIndex=0,online=true,multiCastTime=0,ver=v1.0.0.11,channel=0,reserve=0,lockStatus=null,workMode=null,videoPixerls=null,kvmMode=null,serialNumber=null,sdipPortInfo is null,hdIpPortInfo is null,audioIpPortInfo is null,outputList[SourceOutput [ratio=UHD, url=udp://231.0.100.80:7001, pixel=3840*2160, channel=0, SourceOutput [ratio=HD, url=udp://231.0.101.80:7001, pixel=960*540, channel=0, SourceOutput [ratio=SD, url=udp://231.0.102.80:7001, pixel=352*288, channel=0, SourceOutput [ratio=UHD, url=rtmp://192.168.15.80:1935/live/100, pixel=3840*2160, channel=0, SourceOutput [ratio=HD, url=rtmp://192.168.15.124:1935/live/101, pixel=960*540, channel=0, SourceOutput [ratio=SD, url=rtmp://192.168.15.80:1935/live/102, pixel=352*288, channel=0],callStatus=null]
2020-01-13 13:24:06  INFO [MultiCastDeviceInfoHandler.java:229] - 更新视频合成器设备信息: Device [id=ff8080816f694555016f6a4bf61e158c, code=00:00:01:A6:00:A2, name=192.168.16.80, ip=192.168.16.80, port=0, status=0, type=BHIP118, deviceType=BHIP118-S, stamp=2020-01-03 15:26:00, abilityInfo=null, netCardInfo=null]
2020-01-13 13:24:53  INFO [MultiCastDeviceInfoHandler.java:364] - 更新解码器信息:Decoder [IP=192.168.16.80, Port=0, Channel=0, totalBlocks=36, totalLevel=2, uRefWidth=1920, uRefHeight=1080, audioPort=0, totalPixel=16588800, deviceTypeName=BHIP118-S, pixelsWidth=null, pixelsHeight=null]
2020-01-13 13:25:17  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:25:17  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:25:17  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:25:19  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:25:28  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:25:42  WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null
2020-01-13 13:25:42  ERROR [SqlExceptionHelper.java:144] - wait millis 14463, active 11, maxActive 40, creating 1
2020-01-13 13:25:46  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_playback_task failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:25:48  WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null
2020-01-13 13:25:50  ERROR [SqlExceptionHelper.java:144] - wait millis 18056, active 11, maxActive 40, creating 1
2020-01-13 13:25:50  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_source_volume failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:25:51  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:25:51  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:25:51  INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [null]; error code [0]; Could not open connection; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
2020-01-13 13:25:51  INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
2020-01-13 13:25:58  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_kvm failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:25:56  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:25:56  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:03  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_video_terminal failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:05  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_pic_layer failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:05  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_template failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:05  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_multicast_address failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:08  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_mass_source failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:08  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_pic_encoder_block failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:08  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_ipc_preset_group failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:08  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:13  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_video_terminal failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:17  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_record_layer_block failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:24  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_video_meeting failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:28  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_audio_preset_rlat failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:28  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_preset failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:28  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_layer_block failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:28  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:32  WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null
2020-01-13 13:26:32  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:32  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:32  ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_encoder failed: 
java.lang.OutOfMemoryError: GC overhead limit exceeded
2020-01-13 13:26:52  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:27:07  ERROR [SqlExceptionHelper.java:144] - wait millis 20150, active 12, maxActive 40, creating 1
2020-01-13 13:26:50  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:46  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:46  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:41  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:41  ERROR [SqlExceptionHelper.java:144] - wait millis 23244, active 12, maxActive 40, creating 1
2020-01-13 13:26:41  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:26:41  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:30:29  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:30:25  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:30:07  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:30:07  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1
2020-01-13 13:30:07  WARN [DruidDataSource.java:1258] - get connection timeout retry : 1

这个是组播上报的设备信息,因为组播是一秒钟上报了好几次,是不是这里一直占用着连接

public void run() {
            try {
                ms = new MulticastSocket(multiCastPort);//建立组播套接字
                ms.setReceiveBufferSize(65535);
//              ms.setNetworkInterface(NetworkInterface.getByInetAddress(localAddress));
                ms.joinGroup(InetAddress.getByName(multiCastIP));//加入组播组
                LogHome.getLog().info("正常启动监听" + localAddress.getHostAddress());
                byte[] buffer = null;
                DatagramPacket dp = null;
                while (true) {
                    try { 
                        if (IsStop) {  
                            break;
                        }
                        buffer = new byte[1400];
                        dp = new DatagramPacket(buffer, buffer.length);
                        LogHome.getLog().debug("等待接受组播信息:");
                        ms.receive(dp);
                        MultiCastInfoParser info = new MultiCastInfoParser(dp.getData());
                        DeviceCache.baseInfoOf1004Handler(info.parse());
                    } catch (Exception e) {
                        if (IsStop) {// 如果换网卡可能会出问题
                            break;
                        } else {
                            if (ms.isClosed()) {
                                ms = new MulticastSocket(multiCastPort);
                                ms.setNetworkInterface(NetworkInterface.getByInetAddress(localAddress));
                                ms.joinGroup(InetAddress.getByName(multiCastIP));
                            }
                        }
                         LogHome.getLog().error("接受并设置组播信息失败",e);
                    }finally{
                        Thread.sleep(1);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                try {
                    if (listenerList.containsKey(localAddress.getHostAddress())) {
                        listenerList.remove(localAddress.getHostAddress());
                    }
                } catch (Exception ex) {
                    LogHome.getLog().error(ex);
                }
            }

2个回答

能不能把代码发来看看,怀疑你数据库连接太多了,这么多连接,看着就吓人
qq_23292875
Hefei19881002 回复螃蟹九条腿: 你这代码贴的没头没尾,也不知道你那些方法里是啥,你这主要就是创建了太多数据库连接,解决的方法就是连接超时搞长一点,每次操作数据库都从连接池里拿连接,不要用jdbc的自己在创建连接然后释放,还有你连接池配置一下最大连接数,就这么多了,没看到代码也不知道具体原因,溜了下班了
4 个月之前 回复
qq_23292875
Hefei19881002 回复: 主要看你查数据库的那部分怎么搞得
4 个月之前 回复
qq_23292875
Hefei19881002 回复螃蟹九条腿: 你数据库连接池怎么配置的,超时时间是多少,每查一次就要创建一次连接然后释放,
4 个月之前 回复
weixin_45058835
螃蟹九条腿 回复Hefei19881002: 我应该贴哪部分代码啊,我这边代码太多,几十个controller,我这有一个上次内存异常出现的错误,我给你粘上看看
4 个月之前 回复
qq_23292875
Hefei19881002 回复螃蟹九条腿: 不看代码谁能知道,我只能告诉你数据库连接太多了,你不贴代码我就只能告诉你这么多
4 个月之前 回复
weixin_45058835
螃蟹九条腿 代码太多了啊,就是太多了,不知道在哪里报的错,这是什么引起的啊
4 个月之前 回复

检查下是否session或连接泄漏了,可以参考下这篇博客:https://blog.csdn.net/huanglgln/article/details/41865839

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐