2015-04-04 57 views
1

我使用Wildfly-8.2.0,並有一個像EJB:HornetQ的併發會話使用EJB中

@Singleton 
public class MySingleton { 
    @Inject JMSContext jmsCtx; 

    public void addMessageToQueue(...) { ... } 
} 

和我看到的錯誤: Invalid concurrent session usage. Sessions are not supposed to be used by more than one thread concurrently經常從addMessageToQueue方法的日誌。

由於這是一個單例EJB,因此應用具有默認@Lock(WRITE)的容器管理併發。我不明白這個錯誤是可能的。

+0

你能提供堆棧跟蹤嗎? – 2015-04-05 00:47:28

回答

0

也許,這就是爲什麼這個單一會話用於發送請求並通過偵聽器獲得響應的原因。爲每個任務創建兩個單獨的會話將幫助您。

2

這是WildFly 8.x https://issues.jboss.org/browse/WFLY-3338中的一個已知問題。考慮遷移到WildFly 9(處於測試階段)或使用CDI Instance界面,如WFLY-3338中所建議的。

@Inject 
private Instance<JMSContext> context; 

public void sendMessage(String text, boolean useTopic) { 
    final Destination destination = useTopic ? topic : queue; 
    context.get().createProducer().send(destination, text); 
}