Pablo Fraga [
http://community.jboss.org/people/pablo.fraga1975] created the discussion
"Re: Can't get @TransactionTimeout to work"
To view the discussion, visit:
http://community.jboss.org/message/563409#563409
--------------------------------------------------------------
Jaikiran,
It doesn't work.
This is mi relevant code.
EJB3
@Stateful(name = "DiccionarioEJB")
@Remote(value = RemoteEJBService.class)
public class DiccionarioEJB extends AbstractSessionFacade implements
DiccionarioRemote {
private static Logger log = Logger.getLogger(DiccionarioEJB.class);
@Resource(mappedName = "java:/smsds")
private DataSource dataSource;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@TransactionTimeout(500)
public ResultObtenerDiccionario obtenerDiccionario(AbstractCommand command) {
testConnection();
try {
// sleeps 20 seconds
Thread.sleep(20000);
testConnection();
} catch (Throwable t) {
System.out.println("SUCCESS! Expected tx timeout error");
t.printStackTrace();
return null;
}
return null;
}
private void testConnection() {
Connection conn = null;
try {
conn = this.dataSource.getConnection();
System.out.println("Got connection");
} catch (Throwable t) {
System.out
.println("Error while getting connection from tx aware
datasource: ");
throw new RuntimeException(t);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
System.out.println("Error closing connection "
+ e.getMessage());
}
}
}
}
}
JTA timeout set to 10 seconds
<!-- JBoss Transactions JTA -->
<mbean code="com.arjuna.ats.jbossatx.jta.TransactionManagerService"
name="jboss:service=TransactionManager">
<attribute name="TransactionTimeout">10</attribute>
<attribute
name="ObjectStoreDir">${jboss.server.data.dir}/tx-object-store</attribute>
</mbean>
Log
15:18:07,252 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_58] -
Abort of action id 7f000101:a89c:4c9b9942:32 invoked while multiple threads active within
it.
15:18:07,252 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.CheckedAction_2] -
CheckedAction::check - atomic action 7f000101:a89c:4c9b9942:32 aborting with 1 threads
active!
15:19:24,903 INFO [STDOUT] Error while getting connection from tx aware datasource:
15:19:25,740 INFO [STDOUT] SUCCESS! Expected tx timeout error
15:19:26,723 ERROR [STDERR] java.lang.RuntimeException: org.jboss.util.NestedSQLException:
Transaction is not active: tx=TransactionImple < ac, BasicAction:
7f000101:a89c:4c9b9942:32 status: ActionStatus.ABORTED >; - nested throwable:
(javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac,
BasicAction: 7f000101:a89c:4c9b9942:32 status: ActionStatus.ABORTED >)
In my example the global transaction time out was set to 10 seconds, my EJB method is
annotated with 500 seconds, the EJB method first testConnection, then sleeps 20 seconds
and finally tries to connect again but it fails because the transaccion is not active
anymore.
What is wrong?
Thanks.
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/563409#563409]
Start a new discussion in EJB 3.0 at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]