私のアプリケーションは、JMS メッセージを送受信する Glasssfish AS にデプロイされた EJB を使用します。アプリケーション全体にコンテナ管理のトランザクションがあります。JMS 部分を実行するステートレス EJB は、私のアプリ内の他の多くの EJB によって使用されます。以下のとおりです。
@Stateless
Class BeanJmsHandling{
@Resource(mappedName = "java:app/amqcfp")
private ConnectionFactory connectionFactory;
private Connection connection;
private Session session;
@PostConstruct
public void init(){
connection = connectionFactory.createConnection();
connection.start();
}
public void sendRx(){
//check connection is valid , if not re-open.
//init session.
session=connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue q=session.createTemporaryQueue();
MessageConsumer mc= session.createConsumer(temporaryQueue);
//passing this queue name to an "rmi service" , that sends response on this queue.
rmiService(q.getQueueName());
//read from queue
ObjectMessage m = (ObjectMessage) m.receive(30000);
//close session.
session.close();
}
@PreDestroy
public void closeConnection()
{
//close the connection
}
}
ここでは、接続は SLSB で開かれたままになっているため、毎回接続を開いたり閉じたりするオーバーヘッドを回避できます。多くの場合、ログに以下のエラーが報告されています。
[#|2013-09-02T15:12:54.450+0200|WARNING|glassfish3.1.2|javax.enterprise.system.core.transaction.com.sun.jts.jta|_ThreadID=31;_ThreadName=Thread-2;|JTS5041: The resource manager is doing work outside a global transaction
javax.transaction.xa.XAException: The connection is already closed
at org.apache.activemq.TransactionContext.toXAException(TransactionContext.java:779)
at org.apache.activemq.TransactionContext.setXid(TransactionContext.java:687)
at org.apache.activemq.TransactionContext.start(TransactionContext.java:370)
at org.apache.activemq.ra.LocalAndXATransaction.start(LocalAndXATransaction.java:136)
at com.sun.jts.jta.TransactionState.startAssociation(TransactionState.java:311)
at com.sun.jts.jta.TransactionImpl.enlistResource(TransactionImpl.java:212)
at com.sun.enterprise.transaction.JavaEETransactionImpl.enlistResource(JavaEETransactionImpl.java:639)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistXAResource(JavaEETransactionManagerSimplified.java:1314)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistResource(JavaEETransactionManagerSimplified.java:363)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistComponentResources(JavaEETransactionManagerSimplified.java:1336)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.postInvoke(JavaEETransactionManagerSimplified.java:630)
at com.sun.enterprise.transaction.TransactionInvocationHandler.beforePostInvoke(TransactionInvocationHandler.java:95)
at org.glassfish.api.invocation.InvocationManagerImpl.postInvoke(InvocationManagerImpl.java:201)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2021)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy293.getParameter(Unknown Source)
.......
.......
Caused by: org.apache.activemq.ConnectionClosedException: The connection is already closed
at org.apache.activemq.ActiveMQConnection.checkClosed(ActiveMQConnection.java:1462)
at org.apache.activemq.ActiveMQConnection.checkClosedOrFailed(ActiveMQConnection.java:1449)
at org.apache.activemq.TransactionContext.setXid(TransactionContext.java:684)
... 313 more
[#|2013-09-02T15:13:30.495+0200|WARNING|glassfish3.1.2|javax.enterprise.system.core.transaction.com.sun.jts.jtsxa|_ThreadID=32;_ThreadName=Thread-2;|JTS5067: Unexpected error occurred in commit
javax.transaction.xa.XAException: The connection is already closed
at org.apache.activemq.TransactionContext.toXAException(TransactionContext.java:779)
at org.apache.activemq.TransactionContext.commit(TransactionContext.java:588)
at org.apache.activemq.ra.LocalAndXATransaction.commit(LocalAndXATransaction.java:85)
at com.sun.jts.jtsxa.OTSResourceImpl.commit_one_phase(OTSResourceImpl.java:174)
at com.sun.jts.CosTransactions.RegisteredResources.commitOnePhase(RegisteredResources.java:1565)
at com.sun.jts.CosTransactions.TopCoordinator.commitOnePhase(TopCoordinator.java:2956)
at com.sun.jts.CosTransactions.CoordinatorTerm.commit(CoordinatorTerm.java:321)
at com.sun.jts.CosTransactions.TerminatorImpl.commit(TerminatorImpl.java:250)
at com.sun.jts.CosTransactions.CurrentImpl.commit(CurrentImpl.java:633)
at com.sun.jts.jta.TransactionManagerImpl.commit(TransactionManagerImpl.java:332)
at com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate.commitDistributedTransaction(JavaEETransactionManagerJTSDelegate.java:185)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:861)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5136)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy278.getData(Unknown Source)
...
...
Caused by: org.apache.activemq.ConnectionClosedException: The connection is already closed
at org.apache.activemq.ActiveMQConnection.checkClosed(ActiveMQConnection.java:1462)
at org.apache.activemq.ActiveMQConnection.checkClosedOrFailed(ActiveMQConnection.java:1449)
at org.apache.activemq.TransactionContext.commit(TransactionContext.java:549)
... 83 more
|#]
[#|2013-09-02T15:13:30.504+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.core.transaction.com.sun.jts.CosTransactions|_ThreadID=32;_ThreadName=Thread-2;|JTS5031: Exception [org.omg.CORBA.INTERNAL: vmcid: 0x0 minor code: 0 completed: Maybe] on Resource [commit one phase] operation.|#]
[#|2013-09-02T15:13:30.511+0200|WARNING|glassfish3.1.2|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=32;_ThreadName=Thread-2;|EJB5184:A system exception occurred during an invocation on EJB DataService, method: public java.util.List org.my.DataService.getParameter(java.lang.String,java.util.List,java.lang.Integer,java.lang.Integer)|#]
[#|2013-09-02T15:13:30.512+0200|WARNING|glassfish3.1.2|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=32;_ThreadName=Thread-2;|javax.ejb.EJBException: Unable to complete container-managed transaction.
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5147)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy278.getData(Unknown Source)
.....
.....
Caused by: javax.transaction.SystemException: org.omg.CORBA.INTERNAL: JTS5031: Exception [org.omg.CORBA.INTERNAL: vmcid: 0x0 minor code: 0 completed: Maybe] on Resource [commit one phase] operation. vmcid: 0x0 minor code: 0 completed: No
at com.sun.jts.jta.TransactionManagerImpl.commit(TransactionManagerImpl.java:345)
at com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate.commitDistributedTransaction(JavaEETransactionManagerJTSDelegate.java:185)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:861)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5136)
... 72 more
|#]
何がうまくいかないのかわかりません。誰かが何がうまくいかないのかを理解するために私を導いてくれませんか。
以下の記事を見つけましたが、私の場合、Glassfish で JCA RA が取得されているかどうかは不明です。
https://community.jboss.org/wiki/ShouldIcacheJMSconnectionsandJMSsessions ありがとうございます!