我有java程序發送電子郵件,爲不同的電子郵件地址,我使用的Java線程池的執行,每個線程嘗試發送郵件,然後退出java進程停止無限時間,無法正常退出?
問題是所有線程都將等待狀態,並能再也回不來了運行狀態,即使線程已經完成了他們的成功合作,
我ThreadPoolExecutor的配置如下,
隊列大小= 100 線程數= 5 最大線程數= 10 存活時間= 1分鐘
這裏是線程轉儲,但我不明白什麼是說
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x2808f538> (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.ArrayBlockingQueue.take(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Locked ownable synchronizers:
- None
下面是代碼:
ReqtQueue = new ArrayBlockingQueue<Runnable>(100, true);
notifTaskExecutor = new ThreadPoolExecutor(
5, // core size of threads that will remain in idle state
10, // max size of thread that can be created
1, // keep alive time for thread other than number of core threads when they are in idel state
TimeUnit.MINUTES, // keep alive time units
ReqtQueue // the queue to use
);
而EXCUTE方法被稱爲:
notifTaskExecutor.execute(new NotificationSender(request, name));
的NotificationSender只發送電子郵件和所有的代碼都是在嘗試捕捉其非常簡單,即使run方法是空的線程不被終止
幫助需要
問候
如果您想要,請發佈[SSCCE](http://sscce.org/)示例任何真正的幫助 – tanyehzheng
我懷疑你的線程在一個尚未關閉的池中。我建議你看看其他線程,以確定爲什麼可能是這種情況,也許你有一個僵局。 –
你能給我們一個預覽(最好來自pastebin,你的類有'Threadpool'和'Worker'類嗎?),所以我們知道如何初始化和構建事物? – Killrawr