4 Replies Latest reply on Sep 12, 2014 7:49 AM by Juan Martin Runge

    @TransactionTimeout: Cant make it work!

    Juan Martin Runge Newbie

      Hi,

      I've been trying to use @TransactionTimeout annotation for a method in my EJB and cant manage to make Wildfly respect it.  It uses default transaction timeout value defined in domain.  Is there any hint I should now? I've been googling for an entire day now...  Please tell me if you need to know anything about my setup.  Im running wildfly 8.0.0 final, patched to become 8.1.0 final (if it matters).

       

      Kind regards,

       

      Juan Martin

        • 1. Re: @TransactionTimeout: Cant make it work!
          Frank Langelage Master

          How do you use it? Can you show us some piece of code.

          For me it works just fine in 8.1.0.

          • 2. Re: Re: @TransactionTimeout: Cant make it work!
            Juan Martin Runge Newbie

            Frank,

            Thanks for your response.  Here is a piece of code I found on internet and tried to use, to narrow down my problem:

            import java.lang.reflect.Method;

            import java.util.concurrent.TimeUnit;

            import java.util.logging.Level;

            import java.util.logging.Logger;

            import javax.annotation.Resource;

            import javax.ejb.LocalBean;

            import javax.ejb.Stateless;

            import javax.transaction.Transaction;

            import javax.transaction.TransactionManager;

            import org.jboss.ejb3.annotation.TransactionTimeout;

             

             

            @Stateless

            @LocalBean

            @TransactionTimeout(value=5, unit=TimeUnit.SECONDS)

            public class BeanWithTimeoutValue {

             

             

                @Resource(lookup="java:jboss/TransactionManager")

                private TransactionManager transactionManager;

             

                protected int getTimeout() {

                    try {

                        Transaction tx = transactionManager.getTransaction();

                        Method m = tx.getClass().getMethod("getTimeout", (Class<?>[]) null);

                        return (int) m.invoke(tx, (Object[]) null);

                    } catch (Exception e)

                    {

                        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Error obteniendo transaccion", e);

                        return -1;

                    }

                }

             

             

                /**

                 * This method should inherit transaction timeout specified on bean-level

                 */

                public int getBeanTimeout() {

                    return getTimeout();

                }

             

             

                /**

                 * This method has explicity transaction timeout in bean-class

                 */

                @TransactionTimeout(value=6, unit=TimeUnit.SECONDS)

                public int getBeanMethodTimeout() {

                    return getTimeout();

                }

             

             

                /**

                 * This method  has method-level timeout specified on remote-view

                 */

                public int getRemoteMethodTimeout() {

                    return getTimeout();

                }

             

             

                /**

                 * This method has timeout specified on entire local view

                 */

                public int getLocalViewTimeout() {

                    return getTimeout();

                }

            }

             

            This EJB is called from other Stateless EJB with this code:

            import javax.ejb.Asynchronous;

            import javax.ejb.ConcurrencyManagement;

            import static javax.ejb.ConcurrencyManagementType.BEAN;

            import javax.ejb.LocalBean;

            import javax.ejb.Singleton;

            import javax.inject.Inject;

             

             

            /**

            *

            * @author jmrunge

            */

            @LocalBean

            @Singleton

            @ConcurrencyManagement(BEAN)

            public class MigracionService implements MigracionListener {

                @Inject

                private BeanWithTimeoutValue test;

             

             

             

                @Override

                @Asynchronous

                public void migrar() {

                    System.out.println("getBeanMethodTimeout " + test.getBeanMethodTimeout());

                    System.out.println("getRemoteMethodTimeout " + test.getRemoteMethodTimeout());

                    System.out.println("getLocalViewTimeout " + test.getLocalViewTimeout());

                }   

            }

             

            And this last bean is called from a Vaadin client.  Here I post my pom.xml too (I think perhaps this is something related to use wrong dependencies):

            <?xml version="1.0" encoding="UTF-8"?>

            <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

              xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

              <modelVersion>4.0.0</modelVersion>

              <groupId>ar.com.zir</groupId>

              <artifactId>migracion</artifactId>

              <packaging>war</packaging>

              <version>0.0.1</version>

              <name>migracion</name>

             

             

              <properties>

              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

              <vaadin.version>7.4.0.alpha7</vaadin.version>

              <vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>

              </properties>

              <repositories>

              <repository>

              <id>vaadin-addons</id>

              <url>http://maven.vaadin.com/vaadin-addons</url>

              </repository>

              <repository>

              <id>vaadin-snapshots</id>

              <url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>

              <releases>

              <enabled>false</enabled>

              </releases>

              <snapshots>

              <enabled>true</enabled>

              </snapshots>

              </repository>

                            <repository>

                                    <id>java.net</id>

                                    <url>http://download.java.net/maven/2/</url>

                            </repository>

                            <repository>

                                    <id>smslib-v3</id>

                                    <url>http://smslib.org/maven2/v3</url>

                            </repository>

                    </repositories>

              <pluginRepositories>

              <pluginRepository>

              <id>vaadin-snapshots</id>

              <url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>

              <releases>

              <enabled>false</enabled>

              </releases>

              <snapshots>

              <enabled>true</enabled>

              </snapshots>

              </pluginRepository>

              </pluginRepositories>

              <dependencies>

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-server</artifactId>

              <version>${vaadin.version}</version>

              </dependency>

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-client-compiled</artifactId>

              <version>${vaadin.version}</version>

              </dependency>

              <!--

               Needed when using the widgetset optimizer (custom ConnectorBundleLoaderFactory).

              

               For widgetset compilation, vaadin-client-compiler is automatically added on the

               compilation classpath by vaadin-maven-plugin so normally there is no need for an

               explicit dependency.

              -->

              <!--

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-client-compiler</artifactId>

              <version>${vaadin.version}</version>

              <scope>provided</scope>

              </dependency>

              -->

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-client</artifactId>

              <version>${vaadin.version}</version>

              <scope>provided</scope>

              </dependency>

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-push</artifactId>

              <version>${vaadin.version}</version>

              </dependency>

              <dependency>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-themes</artifactId>

              <version>${vaadin.version}</version>

              </dependency>

              <dependency>

              <groupId>javax.servlet</groupId>

              <artifactId>javax.servlet-api</artifactId>

              <version>3.0.1</version>

              <scope>provided</scope>

              </dependency>

                            <dependency>

                                    <groupId>com.vaadin</groupId>

                                    <artifactId>vaadin-cdi</artifactId>

                                    <version>1.0.0.alpha2</version>

                            </dependency>

                            <dependency>

                                    <groupId>org.jboss.spec.javax.ejb</groupId>

                                    <artifactId>jboss-ejb-api_3.2_spec</artifactId>

                                    <version>1.0.0.Final</version>

              <scope>provided</scope>

                            </dependency>

                    <dependency>

                        <groupId>org.jboss.spec.javax.transaction</groupId>

                        <artifactId>jboss-transaction-api_1.2_spec</artifactId>

                        <version>1.0.0.Final</version>

                        <scope>provided</scope>

                    </dependency>

                    <dependency>

                        <groupId>org.jboss.spec.javax.annotation</groupId>

                        <artifactId>jboss-annotations-api_1.2_spec</artifactId>

                        <version>1.0.0.Final</version>

                        <scope>provided</scope>

                    </dependency>

                    <dependency>

                        <groupId>org.jboss.spec</groupId>

                        <artifactId>jboss-javaee-all-7.0</artifactId>

                        <version>1.0.1.Final</version>

                        <scope>provided</scope>

                    </dependency>

                        <dependency>

                         <groupId>org.jboss.ejb3</groupId>

                         <artifactId>jboss-ejb3-ext-api</artifactId>

                         <version>2.1.0</version>

                        <scope>provided</scope>

                        </dependency>

                        <dependency>

                         <groupId>org.jboss.jbossts</groupId>

                         <artifactId>jbossjta</artifactId>

                         <version>4.16.6.Final</version>

                        <scope>provided</scope>

                        </dependency>

                            <!--dependency>

                                    <groupId>javax</groupId>

                                    <artifactId>javaee-web-api</artifactId>

                                    <version>7.0</version>

              <scope>provided</scope>

                            </dependency-->

                            <dependency>

                                    <groupId>org.hibernate</groupId>

                                    <artifactId>hibernate-entitymanager</artifactId>

                                    <version>4.1.8.Final</version>

                            </dependency>

                            <dependency>

                                    <groupId>coop.ceb.fenix</groupId>

                                    <artifactId>coop.ceb.fenix.api</artifactId>

                                    <version>1.0</version>

                            </dependency>

                            <dependency>

                                    <groupId>coop.ceb.fenix</groupId>

                                    <artifactId>coop.ceb.fenix.utils</artifactId>

                                    <version>1.0</version>

                            </dependency>

                            <dependency>

                                    <groupId>ar.com.kandas</groupId>

                                    <artifactId>kandasframework</artifactId>

                                    <version>1.0</version>

                            </dependency>

                            <dependency>

                                    <groupId>org.postgis</groupId>

                                    <artifactId>postgis-local</artifactId>

                                    <version>1.5</version>

                            </dependency>

                            <dependency>

                                    <groupId>org.postgresql</groupId>

                                    <artifactId>postgresql-local</artifactId>

                                    <version>1.0</version>

                            </dependency>

                            <dependency>

                                <groupId>org.smslib</groupId>

                                <artifactId>smslib</artifactId>

                                <version>3.5.4</version>

                            </dependency>

                            <dependency>

                                <groupId>org.jsmpp</groupId>

                                <artifactId>jsmpp</artifactId>

                                <version>2.1.0</version>

                            </dependency>

                            <dependency>

                                <groupId>log4j</groupId>

                                <artifactId>log4j</artifactId>

                                <version>1.2.17</version>

                            </dependency>

                            <dependency>

                                <groupId>rxtx</groupId>

                                <artifactId>rxtx</artifactId>

                                <version>2.2pre2</version>

                            </dependency>

              </dependencies>

             

             

              <build>

              <plugins>

              <plugin>

              <groupId>org.apache.maven.plugins</groupId>

              <artifactId>maven-compiler-plugin</artifactId>

              <configuration>

              <source>1.8</source>

              <target>1.8</target>

              </configuration>

              </plugin>

              <!-- As we are doing "inplace" GWT compilation, ensure the widgetset -->

              <!-- directory is cleaned properly -->

              <plugin>

              <artifactId>maven-clean-plugin</artifactId>

              <version>2.4.1</version>

              <configuration>

              <filesets>

              <fileset>

              <directory>src/main/webapp/VAADIN/widgetsets</directory>

              </fileset>

              </filesets>

              </configuration>

              </plugin>

              <plugin>

              <groupId>org.apache.maven.plugins</groupId>

              <artifactId>maven-war-plugin</artifactId>

              <version>2.2</version>

              <configuration>

              <failOnMissingWebXml>false</failOnMissingWebXml>

              </configuration>

              </plugin>

              <plugin>

              <groupId>com.vaadin</groupId>

              <artifactId>vaadin-maven-plugin</artifactId>

              <version>${vaadin.plugin.version}</version>

              <configuration>

              <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>

              <!-- <runTarget>mobilemail</runTarget> -->

              <!-- We are doing "inplace" but into subdir VAADIN/widgetsets. This

              way compatible with Vaadin eclipse plugin. -->

              <webappDirectory>${basedir}/src/main/webapp/VAADIN/widgetsets

              </webappDirectory>

              <hostedWebapp>${basedir}/src/main/webapp/VAADIN/widgetsets

              </hostedWebapp>

              <!-- Most Vaadin apps don't need this stuff, guide that to target -->

              <persistentunitcachedir>${project.build.directory}</persistentunitcachedir>

              <deploy>${project.build.directory}/gwt-deploy</deploy>

              <!-- Compile report is not typically needed either, saves hunreds of mb disk -->

              <compileReport>false</compileReport>

              <noServer>true</noServer>

              <!-- Remove draftCompile when project is ready -->

              <draftCompile>false</draftCompile>

             

              <style>OBF</style>

              <strict>true</strict>

              <runTarget>http://localhost:8080/migracion</runTarget>

              </configuration>

              <executions>

              <execution>

              <configuration>

              <!-- if you don't specify any modules, the plugin will find them -->

              <!-- <modules> <module>com.vaadin.demo.mobilemail.gwt.ColorPickerWidgetSet</module>

              </modules> -->

              </configuration>

              <goals>

              <goal>clean</goal>

              <goal>resources</goal>

              <goal>update-theme</goal>

              <goal>update-widgetset</goal>

              <goal>compile-theme</goal>

              <goal>compile</goal>

              </goals>

              </execution>

              </executions>

              </plugin>

              <plugin>

              <groupId>org.mortbay.jetty</groupId>

              <artifactId>jetty-maven-plugin</artifactId>

              <configuration>

               <webApp>

                <contextPath>/migracion</contextPath>

               </webApp>

               <scanIntervalSeconds>5</scanIntervalSeconds>

              </configuration>

              </plugin>

                            </plugins>

              <pluginManagement>

              <plugins>

              <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->

              <plugin>

              <groupId>org.eclipse.m2e</groupId>

              <artifactId>lifecycle-mapping</artifactId>

              <version>1.0.0</version>

              <configuration>

              <lifecycleMappingMetadata>

              <pluginExecutions>

              <pluginExecution>

              <pluginExecutionFilter>

              <groupId>com.vaadin</groupId>

              <artifactId>

              vaadin-maven-plugin

              </artifactId>

              <versionRange>

              [7.4.0.alpha7,)

              </versionRange>

              <goals>

              <goal>resources</goal>

              <goal>update-widgetset</goal>

              <goal>compile</goal>

              <goal>update-theme</goal>

              <goal>compile-theme</goal>

              </goals>

              </pluginExecutionFilter>

              <action>

              <ignore></ignore>

              </action>

              </pluginExecution>

              </pluginExecutions>

              </lifecycleMappingMetadata>

              </configuration>

              </plugin>

              <plugin>

              <artifactId>maven-eclipse-plugin</artifactId>

              <configuration>

              <wtpversion>2.0</wtpversion>

              <additionalProjectnatures>

              <projectnature>com.vaadin.integration.eclipse.widgetsetNature</projectnature>

              </additionalProjectnatures>

              <additionalBuildcommands>

              <buildcommand>com.vaadin.integration.eclipse.widgetsetBuilder</buildcommand>

              <buildcommand>com.vaadin.integration.eclipse.addonStylesBuilder</buildcommand>

              </additionalBuildcommands>

              </configuration>

              </plugin>

              </plugins>

              </pluginManagement>

              </build>

            </project>

             

            Im using Netbeans 8.0 wiht official wildfly maven plugin to develop and deploy the project.

             

            Please let me know if you me to post something else...

             

            Kind Regards,

             

            Juan Martin

            • 3. Re: Re: @TransactionTimeout: Cant make it work!
              Frank Langelage Master

              And your problem is? What does not work? You not get the expected values from getTimeout?

              You should see 6, 5 and 5 as results.

               

              I took your getTimeout method as it is and put it into one of my beans.

              Called within a method annotated with

              @TransactionTimeout(value = 1, unit = TimeUnit.DAYS)
              public void analysis( final Integer messageId, final Date refDate, final Integer plantId, final Integer abcDefinition ) throws MbiException

              gives me the rights value (86400).

               

              What's different:

              - I don't use @LocalBean

              - I don't use @ConcurrencyManagement(BEAN)

              - I use @EJB instead of @Inject

               

              But I think the problem is, that you are already in an transaction in your Singleton and then the BeanWithTimeoutValue methods take over this transaction and timeout changes do not work.

              Please try to add

              @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)

              right before your @TransactionTimeout's and see if this changes the results.

              • 4. Re: Re: Re: @TransactionTimeout: Cant make it work!
                Juan Martin Runge Newbie

                Frank,

                You were right!

                @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)

                Made it work!  I had tested this, but whit WildFly 8.0.0 (and I can swear it was not working at all!), when I patched it to 8.1.0 I forgot to test my code again with this attribute.

                 

                Now everything works as expected.

                 

                Thanks for your time!

                 

                Kind Regards,

                 

                Juan Martin