服务启动后一段时间内,突然内存溢出:Exception in thread “main” java.lang.OutOfMemoryError: PermGen space
第一想的就是jar依赖是不是互相依赖导致的,后来发现并不是
很快找到触发内存不够的那段代码,注释掉
public void receivePrintResult() throws Exception {
Properties properties = new Properties();
properties.setProperty(ConsumerConstants.MafkaBGNamespace, "daocan");
properties.setProperty(ConsumerConstants.MafkaClientAppkey, "orderdish-platform-print-service");
properties.setProperty(ConsumerConstants.SubscribeGroup, "orderdish-platform-print-service");
consumer = MafkaClient.buildConsumerFactory(properties, "owl_print_result_notify");
/* consumer.recvMessageWithParallel(String.class, new IMessageListener() {
@Override
public ConsumeStatus recvMessage(MafkaMessage mafkaMessage, MessagetContext messagetContext) {
try {
String result = (String) mafkaMessage.getBody();
System.out.print(result);
INFO_LOG.info("resultResponse success:{}"+ result);
printResultRedisService.analysePrintResult(result);//处理消息队列
}catch (Exception e){
ERROR_LOG.error("mafka reseivePrintResult#fail Exception:{}",e);
return ConsumeStatus.RECONSUME_LATER;
}
System.out.println("=======================================");
return ConsumeStatus.CONSUME_SUCCESS;
}
});*/
}
采用jvisualvm.exe工具查看内存堆使用情况:
可以看出内存几乎使用完成,导致内存溢出
配置 : -server -XX:PermSize=128M -XX:MaxPermSize=256m
手动扩大内存解决问题