2016-04-28 62 views
0

我有一個兔子消費者,裏面有一個線程池。我決定建立一個線程池,因爲我需要等待計算完成。但正如我注意到的那樣,TP的使用會導致怪異的效果,如凍結等。所以我想問一下,在兔子消費者中使用TP是否正確?使用春季兔子工具可以實現相同的功能嗎?java彈簧消除兔子線程池

... 
ThreadPoolExecutor pool = new ThreadPoolExecutor(cores, 50, 30L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(3000)); 

public void onMessage(){ 

    pool.execute(()->{ 
    //do something 
    handleMessage(...);//return to some output queue 
    }); 

} 

public void onMessage(){ 
     //do something 
     handleMessage(...);//return to some output queue 
    } 
+0

春季rabbitmq工具做的差不多。您是否在使用自動確認功能消息? –

回答

1

一般來說,最好簡單地增加concurrentConsumers在比移交給自己的線程池的偵聽容器。

您的代碼需要線程安全。

使用您當前的解決方案,您將面臨消息丟失的風險,因爲在偵聽器退出時確認消息。