当前位置:编程学习 > JAVA >>

javamail 多线程取邮件 线程hung的问题

用多线程采用IMAP方式读取邮件服务器邮件,平时测试都没问题,各种连接异常啊超时异常啊也都好使,但是运行一天左右时间后,出现线程hung掉的情况,主要是在store.connect的语句那块,直接卡死线程无响应了,线程还在没有当掉,设了connect的timeout,但也不抛异常,也不阻塞,就这么一直Runnable着:线程3033就是那个无响应的.
Full thread dump Java HotSpot(TM) Client VM (20.2-b06 mixed mode):
"Thread-3114" daemon prio=6 tid=0x194af400 nid=0x4b28 runnable [0x1a71f000]
   java.lang.Thread.State: RUNNABLE
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
- locked <0x04bd67c0> (a java.net.SocksSocketImpl)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:297)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:229)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:116)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:115)
at com.sun.mail.imap.IMAPStore.newIMAPProtocol(IMAPStore.java:689)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:638)
- locked <0x04bd3f78> (a com.sun.mail.imap.IMAPStore)
at javax.mail.Service.connect(Service.java:345)
- locked <0x04bd3f78> (a com.sun.mail.imap.IMAPStore)
at javax.mail.Service.connect(Service.java:226)
at com.chanjet.ccs.mail.service.serviceImpl.CommonProvider.archvieEmail(CommonProvider.java:151)
at com.chanjet.ccs.mail.servlet.ArchiveTask.run(ArchiveTask.java:51)
at java.lang.Thread.run(Unknown Source)
"Thread-3033" daemon prio=6 tid=0x194b3000 nid=0x447c runnable [0x1a56f000]
   java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
- locked <0x0a610ba8> (a java.io.BufferedInputStream)
at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:96)
at com.sun.mail.iap.Response.<init>(Response.java:95)
at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:60)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:286)
at com.sun.mail.iap.Protocol.command(Protocol.java:313)
- locked <0x0a610ca8> (a com.sun.mail.imap.protocol.IMAPProtocol)
at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1543)
at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1535)
at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1237)
- locked <0x0a610d78> (a java.lang.Object)
- locked <0x0a610d80> (a com.sun.mail.imap.IMAPMessage)
at com.sun.mail.imap.IMAPMessage.getSentDate(IMAPMessage.java:377)
at com.chanjet.ccs.mail.util.SendDateSearchTerm.match(SendDateSearchTerm.java:20)
at javax.mail.Message.match(Message.java:715)
at javax.mail.Folder.search(Folder.java:1270)
at com.sun.mail.imap.IMAPFolder.search(IMAPFolder.java:1921)
- locked <0x0a610df8> (a com.sun.mail.imap.IMAPFolder)
at javax.mail.Folder.search(Folder.java:1231)
at com.sun.mail.imap.IMAPFolder.search(IMAPFolder.java:1876)
- locked <0x0a610df8> (a com.sun.mail.imap.IMAPFolder)
at com.chanjet.ccs.mail.util.MessageQuerier.getSrchMessagesBySend(MessageQuerier.java:47)
at ....
我想了个办法,用FutureTask包装了下放到自定义的TimeOutThread线程里,线程执行超过10分钟还没结束,就cacel掉这个线程,然后外头再启动一个新线程进来.结果发现一但到了store.connect卡掉那块,旧线程是能cancel掉,但是新起来的线程一直处于timewating状态,都没有进入到run里,也不知道为什么,jconsole跟进去stack信息如下:
Full thread dump Java HotSpot(TM) Client VM (20.2-b06 mixed mode):
"Thread-1317" daemon prio=6 tid=0x19803800 nid=0x4960 waiting on condition [0x1aa3f000]
   java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for  <0x0a829290> (a java.util.concurrent.FutureTask$Sync)
at java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.chanjet.ccs.mail.servlet.TimeOutThread.run(TimeOutThread.java:34)
"RMI TCP Connection(18)-169.254.169.6" daemon prio=6 tid=0x19802c00 nid=0x37c4 runnable [0x1abef000]
   java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
- locked <0x0a35eee8> (a java.io.BufferedInputStream)
at java.io.FilterInputStream.read(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
"RMI TCP Connection(17)-169.254.169.6" daemon prio=6 tid=0x19802400 nid=0x35a8 runnable [0x1ab5f000]
   java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
- locked <0x0a359c68> (a java.io.BufferedInputStream)
at java.io.FilterInputStream.read(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

"RMI TCP Accept-0" daemon prio=6 tid=0x193e3800 nid=0x1ecc runnable [0x1a59f000]
   java.lang.Thread.State: RUNNABLE
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(Unknown Source)
- locked <0x0a327e20> (a java.net.SocksSocketImpl)
at java.net.ServerSocket.implAccept(Unknown Source)
at java.net.ServerSocket.accept(Unknown Source)
at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
"http-bio-80-exec-2" daemon prio=6 tid=0x193e3400 nid=0x1320 waiting on condition [0x1a62f000]
   java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for  <0x0a13da70> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(Unknown Source)
at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32)
at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
"pool-1-thread-1" prio=6 tid=0x193e2800 nid=0x1064 runnable [0x1a50f000]
   java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
- locked <0x0a3fbe48> (a java.io.BufferedInputStream)
at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:96)
at com.sun.mail.iap.Response.<init>(Response.java:95)
at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:60)
at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:286)
at com.sun.mail.iap.Protocol.command(Protocol.java:313)
- locked <0x0a3fbe78> (a com.sun.mail.imap.protocol.IMAPProtocol)
at com.sun.mail.imap.protocol.IMAPProtocol.capability(IMAPProtocol.java:166)
at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:760)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:644)
- locked <0x0a3fbee8> (a com.sun.mail.imap.IMAPStore)
at javax.mail.Service.connect(Service.java:345)
- locked <0x0a3fbee8> (a com.sun.mail.imap.IMAPStore)
at javax.mail.Service.connect(Service.java:226)
 com.chanjet.ccs.mail.service.serviceImpl.CommonProvider.archvieEmail(CommonProvider.java:151)
at com.chanjet.ccs.mail.servlet.ArchiveTask.call(ArchiveTask.java:51)
at com.chanjet.ccs.mail.servlet.ArchiveTask.call(ArchiveTask.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
也没检测出死锁,也不知道是为什么,求帮助
javamail 多线程 javamail 多线程 --------------------编程问答-------------------- 算了,自己顶下继续研究... --------------------编程问答-------------------- 这么大段的出错信息 还没有你的源码 无法判断错误.
补充:Java ,  Java相关
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,