簡體   English   中英

ActiveMQ和ThreadPoolExecutor一起工作

[英]ActiveMQ and ThreadPoolExecutor working together

我需要從activeMQ中獲取數據,然后將其傳遞給在ThreadPoolExecutor中運行的執行程序。

問題是,我不必從隊列中獲取下一個數據,直到池中至少有一個線程處於空閑狀態,准備執行此任務。

我可以等到activeCount <poolSize。 但是,對於任何對此方法進行異步處理的解決方案,我將不勝感激。 提前致謝。

你可以試試這個

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