简体   繁体   English

ActiveMQ和ThreadPoolExecutor一起工作

[英]ActiveMQ and ThreadPoolExecutor working together

I need to fetch the data from activeMQ and then pass it to executors running in ThreadPoolExecutor. 我需要从activeMQ中获取数据,然后将其传递给在ThreadPoolExecutor中运行的执行程序。

The problem is, I don't have to fetch next data from queue, until I have at least one thread in the pool sitting idle, ready to take on this task. 问题是,我不必从队列中获取下一个数据,直到池中至少有一个线程处于空闲状态,准备执行此任务。

I can just busy wait until activeCount< poolSize. 我可以等到activeCount <poolSize。 But I would appreciate any solution with some asynchronous handling of this. 但是,对于任何对此方法进行异步处理的解决方案,我将不胜感激。 Thanks in advance. 提前致谢。

You can try this 你可以试试这个

final ThreadPoolExecutor executor=...
new Thread(new Runnable(){
public void run(){
    while(true){
        if(executor.getActiveCount()<executor.getCorePoolSize())
            executor.execute(mq.get());
      }
}).start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM