2019/07/30-09:40:34 [localhost-startStop-1] WARN org.apache.catalina.loader.WebappClassLoaderBase - The web application [iot-ms] appears to have started a thread named [HikariPool-1 housekeeper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
java.util.concurrent.locks.AbstractQueuedSynchronizer C o n d i t i o n O b j e c t . a w a i t N a n o s ( A b s t r a c t Q u e u e d S y n c h r o n i z e r . j a v a : 2078 ) j a v a . u t i l . c o n c u r r e n t . S c h e d u l e d T h r e a d P o o l E x e c u t o r ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078) java.util.concurrent.ScheduledThreadPoolExecutor ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)java.util.concurrent.ScheduledThreadPoolExecutorDelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
java.util.concurrent.ScheduledThreadPoolExecutor D e l a y e d W o r k Q u e u e . t a k e ( S c h e d u l e d T h r e a d P o o l E x e c u t o r . j a v a : 809 ) j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r . g e t T a s k ( T h r e a d P o o l E x e c u t o r . j a v a : 1074 ) j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r . r u n W o r k e r ( T h r e a d P o o l E x e c u t o r . j a v a : 1134 ) j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809) java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134) java.util.concurrent.ThreadPoolExecutor DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)java.util.concurrent.ThreadPoolExecutorWorker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
2019/07/30-09:40:34 [localhost-startStop-1] WARN org.apache.catalina.loader.WebappClassLoaderBase - The web application [iot-ms] appears to have started a thread named [lettuce-eventExecutorLoop-2-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
io.netty.util.concurrent.SingleThreadEventExecutor.takeTask(SingleThreadEventExecutor.java:251)
io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:64)
io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
java.lang.Thread.run(Thread.java:748)
1.错误分析
这种情况有可能是在启动的时候,某个东西重复被初始化,导致内存溢出或者其它。分析找到错误的地方如下:
那么这里会有什么问题呢?
1、访问的路由重复
2、接收数据对象PostDeviceCommandOutDTO2接收数据初始化错误。
初步排除1的可能性,那么只能是2的原因了,那么我们一起来看一下这个对象里面有什么?
package com.iotplatform.client.dto;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class PostDeviceCommandOutDTO2 {
private String commandId;
private String appId;
private String deviceId;
private CommandDTOV4 command;
private String callbackUrl;
private Integer expireTime;
private String status;
private ObjectNode result;
private String creationTime;
private String executeTime;
private String platformIssuedTime;
private String deliveredTime;
private Integer issuedTimes;
private Integer maxRetransmit;
public PostDeviceCommandOutDTO2() {
}
public String getCommandId() {
return this.commandId;
}
public void setCommandId(String commandId) {
this.commandId = commandId;
}
public String getAppId() {
return this.appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getDeviceId() {
return this.deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public CommandDTOV4 getCommand() {
return this.command;
}
public void setCommand(CommandDTOV4 command) {
this.command = command;
}
public String getCallbackUrl() {
return this.callbackUrl;
}
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}
public Integer getExpireTime() {
return this.expireTime;
}
public void setExpireTime(Integer expireTime) {
this.expireTime = expireTime;
}
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
public ObjectNode getResult() {
return this.result;
}
public void setResult(ObjectNode result) {
this.result = result;
}
public String getCreationTime() {
return this.creationTime;
}
public void setCreationTime(String creationTime) {
this.creationTime = creationTime;
}
public String getExecuteTime() {
return this.executeTime;
}
public void setExecuteTime(String executeTime) {
this.executeTime = executeTime;
}
public String getPlatformIssuedTime() {
return this.platformIssuedTime;
}
public void setPlatformIssuedTime(String platformIssuedTime) {
this.platformIssuedTime = platformIssuedTime;
}
public String getDeliveredTime() {
return this.deliveredTime;
}
public void setDeliveredTime(String deliveredTime) {
this.deliveredTime = deliveredTime;
}
public Integer getIssuedTimes() {
return this.issuedTimes;
}
public void setIssuedTimes(Integer issuedTimes) {
this.issuedTimes = issuedTimes;
}
public Integer getMaxRetransmit() {
return this.maxRetransmit;
}
public void setMaxRetransmit(Integer maxRetransmit) {
this.maxRetransmit = maxRetransmit;
}
public String toString() {
return "PostDeviceCommandOutDTO2 [commandId=" + this.commandId + ", appId=" + this.appId + ", deviceId=" + this.deviceId + ", command=" + this.command + ", callbackUrl=" + this.callbackUrl + ", expireTime=" + this.expireTime + ", status=" + this.status + ", result=" + this.result + ", creationTime=" + this.creationTime + ", executeTime=" + this.executeTime + ", platformIssuedTime=" + this.platformIssuedTime + ", deliveredTime=" + this.deliveredTime + ", issuedTimes=" + this.issuedTimes + ", maxRetransmit=" + this.maxRetransmit + "]";
}
}
可以看出来这就是个简单的bean,没有什么特别的,但是你会发现
ObjectNode这个对象不能够序列化,在初始化的时候,不断去初始化这个对象,导致内存溢出,线程暴露出不安全,到此完美解决。