2016-12-15 70 views
1

我們有一個應用程序,分佈在大約100個作業中的75個分區步驟。我們對出站網關配置爲:JmsOutboundGateway:手動啓動和停止

<int-jms:outbound-gateway 
    id="outbound-gateway_1" 
    auto-startup="true" 
    connection-factory="jmsConnectionFactory" 
    request-channel="jms.requests_1" 
    request-destination="jms.requestsQueue" 
    reply-channel="jms.reply_1" 
    reply-destination="jms.repliesQueue" 
    receive-timeout="${timeout}" 
    correlation-key="JMSCorrelationID" > 
    <int-jms:reply-listener receive-timeout="1000"/> 
</int-jms:outbound-gateway> 

當自動啓動=「真」,我們看到了每個出站網關replyListener線程。爲了消除這種額外的負載和資源消耗,我們更改爲autostart =「false」,併爲分區步驟添加了一個步驟偵聽器,以便在beforeStep和afterStep方法中啓動和停止網關。在服務器啓動時,replyListener線程不在預期的位置。它們在步驟執行期間出現,但在呼出後停止在出站網關上(即使等待長時間後)也不會被刪除。

清理replyListener是否需要其他東西?

+0

你怎麼知道那些線程仍然存在?你使用哪個版本的Spring Integration?謝謝 –

回答

0

好的,我明白你的意思了。這看起來像:

while ((active = isActive()) && !isRunning()) { 
    if (interrupted) { 
     throw new IllegalStateException("Thread was interrupted while waiting for " + 
       "a restart of the listener container, but container is still stopped"); 
    } 
    if (!wasWaiting) { 
      decreaseActiveInvokerCount(); 
    } 
    wasWaiting = true; 
    try { 
     lifecycleMonitor.wait(); 
    } 
    catch (InterruptedException ex) { 
     // Re-interrupt current thread, to allow other threads to react. 
     Thread.currentThread().interrupt(); 
     interrupted = true; 
    } 
} 
DefaultMessageListenerContainer.AsyncMessageListenerInvoker.executeOngoingLoop()

lifecycleMonitor.wait();和注意IllegalStateException的消息。

不知道這樣的設計的目的是什麼,但我們不會有選擇,除非住在那樣。

此外,start()中的邏輯基於this.pausedTasks本地緩存,其在doInitialize()(如果容器!this.running)期間填充。

隨意提出JIRA,如果您認爲必須以某種方式更改邏輯。

+0

我們所有的分區分區作業都聽同一個JMS隊列並使用不同的通道。有沒有一種方法來配置出站網關使用相同的replyListener實例,他們只需要運行1(擺脫開始和停止? –

+0

考慮不要使用'我甚至不確定你需要靜態的'reply-destination'作爲你的動態樣本,'TemporaryQueue'解決方案應該足夠了 –

+0

使用一個偏好短期任務的外部任務執行器,或者明確設置'max-messages每個任務的最大消息大於0時,線程將終止(或放回池中),而不是在該監視器上阻塞。 –