0

我的应用程序使用部署在 Glasssfish AS 中的 EJB,用于发送和接收 JMS 消息。整个应用程序都有容器管理的事务。我的应用程序中的许多其他 EJB 都使用了执行 JMS 部分的无状态 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 谢谢!

4

1 回答 1

1

只需使用消息驱动的 bean;连接和会话由容器自动管理。

于 2013-09-14T12:58:43.990 回答