生產環境
CentOS release 6.5 (Final) 8核16G
多個tomcat實例,使用zookeeper分佈式服務做線性擴展,最後log中的報錯
2017-03-10 21:00:18,953 [DubboServerHandler-192.168.1.86:28081-thread-187] DEBUG *.*.*.service.aop.LoggingAspect - 退出方法: *.*.*.service.api.SessionServiceImpl.hasExpired() 返回 = false
2017-03-10 21:00:18,954 [DubboServerHandler-192.168.1.86:28081-thread-173] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
WARN [com.alibaba.druid.pool.DruidDataSource] get/close not same thread
WARN [com.alibaba.druid.pool.DruidDataSource] get/close not same thread
WARN [com.alibaba.druid.pool.DruidDataSource] get/close not same thread
WARN [com.alibaba.druid.pool.DruidDataSource] get/close not same thread
WARN [com.alibaba.druid.pool.DruidDataSource] get/close not same thread
WARN [com.alibaba.druid.pool.DruidDataSource] get/close not same thread
網上查了好多資料,都是隻有報錯,沒有寫導致原因,沒有給解決。經排查所有log,在一個tomcat實例中的log有OutOfMemoryError的報錯,斷定是OutOfMemoryError,導致服務不可用
2017-03-10 21:00:18,912 [DubboServerHandler-192.168.1.86:28081-thread-169] ERROR com.alibaba.dubbo.rpc.filter.ExceptionFilter - [DUBBO] Got unchecked and undeclared exception which called by 192.168.1.62. service: *.*.*.service.api.ThirdSystemService, method: getDeviceMatchList, exception: java.lang.OutOfMemoryError: Java heap space, dubbo version: 2.5.3, current host: 127.0.0.1
codereview getDeviceMatchList方法發現,匹配設備將近51萬,而且使用List 中的addAll彙總,使得內存溢出。
list.addAll(userDeviceDao.getLoginDeviceIdMatchList(params));
list.addAll(userDeviceDao.getRegisterDeviceIdMatchList(params));
/**
* Appends all of the elements in the specified collection to the end of
* this list, in the order that they are returned by the
* specified collection's Iterator. The behavior of this operation is
* undefined if the specified collection is modified while the operation
* is in progress. (This implies that the behavior of this call is
* undefined if the specified collection is this list, and this
* list is nonempty.)
*
* @param c collection containing elements to be added to this list
* @return <tt>true</tt> if this list changed as a result of the call
* @throws NullPointerException if the specified collection is null
*/
public boolean addAll(Collection<? extends E> c) {
Object[] a = c.toArray();
int numNew = a.length;
ensureCapacityInternal(size + numNew); // Increments modCount
System.arraycopy(a, 0, elementData, size, numNew);
size += numNew;
return numNew != 0;
}