我需要从activeMQ获取数据,然后将其传递给在ThreadPoolExecutor中运行的执行器。
问题是,我不必从队列中获取下一个数据,直到池中至少有一个线程处于空闲状态,准备执行此任务。
我可以忙着等activeCount< poolSize。但我希望任何解决方案都能对此进行一些异步处理。提前谢谢。
发布于 2016-10-06 18:22:53
你可以试试这个
final ThreadPoolExecutor executor=...
new Thread(new Runnable(){
public void run(){
while(true){
if(executor.getActiveCount()<executor.getCorePoolSize())
executor.execute(mq.get());
}
}).start();https://stackoverflow.com/questions/39892973
复制相似问题