我已经实现了我自己的线程池执行器,如下所示,
private final Queue<?> inProgressQueue;
private final Queue<?> pendingQueue;
public ThreadPoolExecutorImpl(int corePoolSize, int maximumQueueSize, long keepAliveTime, TimeUnit unit) {
super(PoolSize, PoolSize, keepAliveTime, unit, new LinkedBlockingQueue<Runnable>());
this.maximumQueueSize = maximumQueueSize;
this.inProgressQueue = new ConcurrentLinkedQueue<>();
this.pendingQueue = new ConcurrentLinkedQueue<>();
}
消费者:
public class Consumer implements MessageListener {
@Override
public void onMessage(Message message) {
Future<?> obj= pool.submit(new CallableClass(id, this));
}
}
CallableClass:
public class Callableclass extends callable{
@Override
public String call() {
Thread.sleep(10000);
//code
}
}
使用上述代码可以正常工作2到3天而不会出现任何问题。但经过4天的消费者,它已被停止,但有以下例外,
java.lang.OutOfMemoryError: GC overhead limit exceeded at
java.util.concurrent.LinkedBlockingQueue.offer(LinkedBlockingQueue.java:415)
java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1364)..
任何人都可以帮助我,为什么会发生这种情况?以及如何解决此问题。或者我应该使用Runnable吗?