2

I am experiencing problems with @Asynchronous methods, I have to make some external http requests whilst in the middle of a processing job, I want to do these async so they do not delay the main processing job.

I have found that when the main job is invoked from a Restful API call (using RESTEasy) the Async methods work fine, but when the job is invoked from user interaction (eg. a JSF request) the Async method is triggered but the main thread then loses its transaction and I get the exceptions shown below.

I have tried a number of things including:

-Marking the Async method with annotation 'REQUIRES_NEW'

-Marking the calling method with transaction 'REQUIRED'

-Using the Seam annotation 'org.jboss.seam.annotations.async.Asynchronous' instead of EJB 3.1 (gets same results)

-Put Async method in @Stateful bean rather than @Stateless

I think this may be some issue with SEAM / EJB configuration, I have the following in components.xml

<component class="org.jboss.seam.async.TimerServiceDispatcher" jndi-name="java:app/jboss-seam/TimerServiceDispatcher"/>
    <!-- EJB dispatcher for seam -->
    <component class="org.jboss.seam.transaction.EjbSynchronizations" jndi-name="java:app/jboss-seam/EjbSynchronizations"/>

Running Seam 2.3.1 and EJB 3.1 on JBoss AS 7.2

Here is the calling class:

@AutoCreate
@Name("processSession")
public class ProcessSession implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Logger private Log log;
    @In private MakeRequestAsync makeRequestAsync;

    public Session processSessionForUser(User user, Session session){

        //Some processing

        makeRequestAsync.makeRequestAsync(user,session);

        //Some more processing

    }
}

...and here is the async method

@Stateless
@Name("makeRequestAsync")
public class MakeRequestAsyncActions implements MakeRequestAsync, Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public void makeRequestAsync(User user, Session session){

        //Calls another stateless EJB 

        makeRequestActions.makeRequestActions(user,session);

    }
}

/**
 * Interface for Make Request actions 
 */
@Local
public interface MakeRequestAsync {

    @Asynchronous
    void makeRequestAsync(Session session, User user);

}

Exception thrown in main thread after Async method is called:

15:01:21,353 DEBUG [uk.co.app.session.processing.ProcessRace] (ajp-localhost/127.0.0.1:8009-1) invoking makeRequestAsync as async method
15:01:21,577 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ajp-localhost/127.0.0.1:8009-1) SQL Error: 0, SQLState: null
15:01:21,577 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ajp-localhost/127.0.0.1:8009-1) javax.resource.ResourceException: IJ000460: Error checking for a transaction
15:01:21,585 ERROR [org.jboss.as.ejb3] (ajp-localhost/127.0.0.1:8009-1) javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Could not open connection
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) [hibernate-entitymanager-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310) [hibernate-entitymanager-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:273) [hibernate-entitymanager-4.2.0.CR1.jar:4.2.0.CR1]
    at uk.co.app.dao.generic.GenericDAOBean.findAll(GenericDAOBean.java:96) [:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [classes.jar:1.6.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [classes.jar:1.6.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [classes.jar:1.6.0_65]
    at java.lang.reflect.Method.invoke(Method.java:597) [jrebel-bootstrap-8990ba1ce94a90c93f43ef94686abe1e.jar:1.6.0_65]
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.2.0.Final.jar:7.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58) [jboss-as-ee-7.2.0.Final.jar:7.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:79) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) [jboss-seam.jar:2.3.1.Final]
    at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:51) [jboss-seam.jar:2.3.1.Final]
    at sun.reflect.GeneratedMethodAccessor81.invoke(Unknown Source) [:1.6.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [classes.jar:1.6.0_65]
    at java.lang.reflect.Method.invoke(Method.java:597) [jrebel-bootstrap-8990ba1ce94a90c93f43ef94686abe1e.jar:1.6.0_65]
    at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:123) [jboss-as-ee-7.2.0.Final.jar:7.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58) [jboss-as-ee-7.2.0.Final.jar:7.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [jboss-as-ejb3-7.2.0.Final.jar:7.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [jboss-as-jpa-7.2.0.Final.jar:7.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.2.0.Final.jar:7.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.2.0.Final.jar:7.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:226) [jboss-as-ejb3-7.2.0.Final.jar:7.2.0.Final]
    ... 187 more
Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:221) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:56) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:161) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:159) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1854) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1831) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.Loader.doQuery(Loader.java:899) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.Loader.doList(Loader.java:2516) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.Loader.doList(Loader.java:2502) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.Loader.list(Loader.java:2327) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1246) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:264) [hibernate-entitymanager-4.2.0.CR1.jar:4.2.0.CR1]
    ... 232 more
Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000460: Error checking for a transaction
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:147)
    at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70) [hibernate-entitymanager-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
    ... 252 more
Caused by: javax.resource.ResourceException: IJ000460: Error checking for a transaction
    at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:362)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:464)
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:139)
    ... 255 more
Caused by: javax.resource.ResourceException: IJ000459: Transaction is not active: tx=TransactionImple < ac, BasicAction: 0:ffffc0a80155:-286ea3e8:55fc17c4:7f status: ActionStatus.ABORT_ONLY >
    at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:352)
    ... 257 more
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
DaveB
  • 2,953
  • 7
  • 38
  • 60

0 Answers0