【发布时间】:2015-08-25 06:44:42
【问题描述】:
我有一个自定义线程池执行器
public class CustomTPExecutor extends ThreadPoolExecutor
{
/* Constructor called from my processor */
public CustomTPExecutor (int corePoolSize, int maxPoolSize, long keepAliveTime,
TimeUnit timeUnit, BlockingQueue<Runnable> blockingQueue,
ThreadFactory threadFactory,Processor processor)
{
super(corePoolSize, maxPoolSize, keepAliveTime, timeUnit, blockingQueue,threadFactory);
this.processor = processor;
}
@Override
protected void afterExecute(Runnable paramRunnable, Throwable paramThrowable)
{
super.afterExecute(paramRunnable, paramThrowable);
/* Notify the processor to get more records */
}
}
在我的处理器中,我将为这个 customTPExecutor 创建实例并向它提交超过 1000 个任务。最大池大小为 5。
为了将它提交给执行者,我们使用它。
while(iterating map events containing 1000+records) {
CustomThread tt = new TxnTCustomThread(eventMap.get(key), key,maxDate,connPool,connPool.getConnection(),email);
executor.submit(tt);
}
处理完所有记录后,我们调用执行器关闭方法。
我们注意到的一件事是,当线程正在执行时,它会在处理过程中挂起一段时间。它暂停一分钟左右,然后继续处理记录。我不确定这是什么原因。
我假设这是因为垃圾收集没有正确发生。我也无法从日志中获取任何信息来对此进行调试。在此过程中,java 的内存消耗大大减少。
任何有关如何解决此问题的建议都会非常有帮助。
【问题讨论】:
-
建议加
-verbose:gc查看stop the world pauses和GC基本信息。
标签: java multithreading garbage-collection executorservice threadpoolexecutor