0 Replies Latest reply on Dec 30, 2015 1:29 PM by vamshi appala

    Wildfly 9 clustered programmatic timer

    vamshi appala Newbie

      Hello,

      I have followed the below instructions to setup clustered timers so that only one node will execute the timers.

       

       

      https://docs.jboss.org/author/display/WFLY9/EJB3+Clustered+Database+Timers

      http://www.mastertheboss.com/jboss-server/wildfly-8/creating-clustered-ejb-3-timers

       

       

      Below is the configuration that I have defined in standalone.xml

      <xa-datasource jndi-name="java:/jdbc/clusterTimer" pool-name="clusterXADSTimer" enabled="true" use-ccm="true">

      <xa-datasource-property name="DatabaseName">

      </xa-datasource-property>

      <xa-datasource-property name="User">

      </xa-datasource-property>

      <xa-datasource-property name="ServerName">

      localhost

      </xa-datasource-property>

      <xa-datasource-property name="PortNumber">

      31002

      </xa-datasource-property>

      <xa-datasource-property name="Password">

      </xa-datasource-property>

      <driver>org.postgresql</driver>

      <new-connection-sql>select 1</new-connection-sql>

      <transaction-isolation>TRANSACTION_SERIALIZABLE</transaction-isolation>

      <xa-pool>

      <min-pool-size>10</min-pool-size>

      <max-pool-size>50</max-pool-size>

      <prefill>true</prefill>

      </xa-pool>

      <security>

      <user-name>XXXX</user-name>

      <password>${VAULT::ds_IceCube::password::1}</password>

      </security>

      <validation>

      <check-valid-connection-sql>select 1</check-valid-connection-sql>

      </validation>

      </xa-datasource>

       

         <timer-service thread-pool-name="default" default-data-store="clustered-store">

      <data-stores>

      <database-data-store name="clustered-store" datasource-jndi-name="java:/jdbc/ clusterTimer " database="postgresql" partition="timer"/>

      </data-stores>

      </timer-service>

       

      With this configuration I have deployed application with timer configured using @scheduled, timer defined using scheduled works properly. Only one node executes the timer and I can see entry in the database.

      However when I create the persistence timer programmatically, I see two entries being created in the DB and timers run on each node. How can we define timer programmatically so that only one node will be running the timer

       

       

             @Resource

             private TimerService timerService;

             timerService.createTimer(TIMER_INTERVAL,TIMER_INTERVAL, "programattic timer 123");


      In have also seen that time occasionally throws following exception for scheduled timer


      2015-12-30 10:29:49,006 ERROR [org.jboss.as.ejb3] (EJB default - 2) WFLYEJB0164: Exception running timer task for timer [id=ff7495af-88d2-488d-82d7-78403550aa25 timedObjectId=cluster-timer-test.cluster-timer-test.SessionCleanUpBean auto-timer?:true persistent?:true timerService=org.jboss.as.ejb3.timerservice.TimerServiceImpl@6973c03b initialExpiration=null intervalDuration(in milli sec)=0 nextExpiration=Wed Dec 30 10:19:00 CST 2015 timerState=ACTIVE info=null] on EJB cluster-timer-test.cluster-timer-test.SessionCleanUpBean: java.lang.RuntimeException: java.lang.RuntimeException: org.postgresql.util.PSQLException: ERROR: could not serialize access due to concurrent update

        at org.jboss.as.ejb3.timerservice.TimerServiceImpl.persistTimer(TimerServiceImpl.java:628) [wildfly-ejb3-9.0.2.Final.jar:9.0.2.Final]

        at org.jboss.as.ejb3.timerservice.task.CalendarTimerTask.postTimeoutProcessing(CalendarTimerTask.java:105) [wildfly-ejb3-9.0.2.Final.jar:9.0.2.Final]

        at org.jboss.as.ejb3.timerservice.task.TimerTask.run(TimerTask.java:175) [wildfly-ejb3-9.0.2.Final.jar:9.0.2.Final]

        at org.jboss.as.ejb3.timerservice.TimerServiceImpl$Task$1.run(TimerServiceImpl.java:1236) [wildfly-ejb3-9.0.2.Final.jar:9.0.2.Final]

        at org.wildfly.extension.requestcontroller.RequestController$QueuedTask$1.run(RequestController.java:496) [wildfly-request-controller-1.0.2.Final.jar:1.0.2.Final]

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_80]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_80]

        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_80]

        at org.jboss.threads.JBossThread.run(JBossThread.java:320) [jboss-threads-2.2.0.Final.jar:2.2.0.Final]

      Caused by: java.lang.RuntimeException: org.postgresql.util.PSQLException: ERROR: could not serialize access due to concurrent update