由于OutOfMemory,ThreadPool陷入了awaitTermination

时间:2017-03-02 09:58:50

标签: java out-of-memory threadpool

ExecutorService executor = Executors.newFixedThreadPool(poolSize);
try {
   try {
      for (Worker workerItem: workers) {
        executor.execute(workerItem);
      }
   } finally {
         executor.shutdown();
         executor.awaitTermination(1, TimeUnit.DAYS);
   }
} catch (Throwable) {
   e.printStackTrace();
}

Follwing代码结构反映了实际代码。我们遇到了一个严重的问题 - 我们有一个引起OutofMemoryError的尖峰。系统恢复了一段时间后。

[memory ][Wed Feb 22 20:53:03 2017][23193] [OC#2194] 432865.981-432866.802: OC 8023932KB->899782KB (8388608KB), 0.821 s, sum of pauses 515.616 ms, longest pause 515.616 ms.
[thread ][Wed Feb 22 20:53:06 2017][23193] Could not start thread CCBSubmitPool-Thread13753. Resource temporarily unavailable
[memory ][Wed Feb 22 20:53:06 2017][23193] Throwing OutOfMemory: Resource temporarily unavailable in tsStartJavaThread (lifecycle.c:1097).

问题是有50名工人安排,但第三名未能启动。结果,线程池陷入了awaitTermination。这是应用程序的一个非常关键的部分。想法是检测这种状态并执行某些动作。问题是 - 有没有办法确定这种状态?

感谢

修改。 此示例(Could not start more threads despite using Executors)完美地显示了该问题。 16382nd线程被拒绝,线程池在awaitTermination中等待,直到超时结束。

0 个答案:

没有答案