简体   繁体   中英

ActiveMQ and ThreadPoolExecutor working together

I need to fetch the data from activeMQ and then pass it to executors running in 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. 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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