6 Replies Latest reply on Jun 26, 2013 4:29 AM by Wolf-Dieter Fink

    How to create a scheduler in jboss 7

    winston sanker Newbie

      Hi i'm trying to create a automatic scheduler in Jboss 7 , which starts automatically once it is deployed . I followed a tutorial on the net . But could'nt get it working. Please help me in resolving this.

       

      The only class I hav is AutomaticSchedulerBean.java and the source is as follows :

       

      AutomaticSchedulerBean.java

      ------------------------------------------------------------

      package test;

      import javax.ejb.Stateless;

      import java.util.Date;

      import javax.ejb.Schedule;

       

       

      @Stateless(name="AutomaticSchedulerBean")

      public class AutomaticSchedulerBean

      {

          @Schedule(dayOfWeek = "*", hour = "*", minute = "*", second = "*/5", persistent = false)

           public void backgroundProcessing()

                    {

                             System.out.println("\n\n\t AutomaticSchedulerBean's backgroundProcessing() called....at: "+new Date());

                             System.out.println("called ma boy");

                    }

      }

       

      ---------------------------------------------------------------------

       

      I've attached the build.xml with this post. My ant build deploys the jar into standalone\deploy folder . Once its deployed the server gives the following info in console

       

        java:global/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:app/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:module/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:global/schedulerEJB/AutomaticSchedulerBean

                java:app/schedulerEJB/AutomaticSchedulerBean

                java:module/AutomaticSchedulerBean

       

      But the scheduled job is not processed according to @Schedule. Please help me fix it.

       

      Thanks in Advance

        • 1. Re: How to create a scheduler in jboss 7
          Wolf-Dieter Fink Master

          This should be working every 5sec.

           

          Are you sure you did not hide the system.out?

          What version of AS7 you use, how the logfile look like.

           

          BTW for such approach you might use a @Singleton instead of @Stateless

          • 2. Re: How to create a scheduler in jboss 7
            winston sanker Newbie

            I'm using jboss-as-web-7.0.2.Final . I tried singleton also . The build file is same as i attached above . But dint work . The source as follows :

             

            package test;

            import javax.ejb.Stateless;

            import java.util.Date;

            import javax.ejb.Schedule;

            import javax.ejb.Singleton;

            import javax.ejb.Startup;

             

            @Startup 

            @Singleton(name="AutomaticSchedulerBean")

            public class AutomaticSchedulerBean

            {

                 @Schedule(hour = "*", minute = "*", second = "*/5",year="2013", persistent = false)

                 public void backgroundProcessing()

                    {

                       System.out.println("\n\n\t AutomaticSchedulerBean's backgroundProcessing() called....at: "+new Date());

                       System.out.println("called ma boy");

                    }

            }

             

             

            -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

             

            Server log as follows :

             

            09:07:32,192 INFO  [org.jboss.as.connector.subsystems.datasources] (Controller Boot Thread) Deploying JDBC-compliant driver class org.h2.Driver (version 1.2)

            09:07:32,224 INFO  [org.jboss.as.clustering.infinispan.subsystem] (Controller Boot Thread) Activating Infinispan subsystem.

            09:07:32,364 INFO  [org.jboss.as.naming] (Controller Boot Thread) JBAS011800: Activating Naming Subsystem

            09:07:32,380 INFO  [org.jboss.as.naming] (MSC service thread 1-5) JBAS011802: Starting Naming Service

            09:07:32,395 INFO  [org.jboss.as.osgi] (Controller Boot Thread) JBAS011910: Activating OSGi Subsystem

            09:07:32,411 INFO  [org.jboss.as.security] (Controller Boot Thread) Activating Security Subsystem

            09:07:32,427 INFO  [org.jboss.remoting] (MSC service thread 1-7) JBoss Remoting version 3.2.0.Beta2

            09:07:32,724 INFO  [org.xnio] (MSC service thread 1-7) XNIO Version 3.0.0.Beta3

            09:07:32,770 INFO  [org.xnio.nio] (MSC service thread 1-7) XNIO NIO Implementation Version 3.0.0.Beta3

            09:07:33,192 INFO  [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-3) The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;native;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Windows Imaging\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.6.0_31\bin;D:\RSP Softwares\jboss-as-web-7.0.2.Final\jboss-as-web-7.0.2.Final\bin;C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin;C:\apache-ant-1.9.1\bin;C:\Documents and Settings\sesa276545\Desktop\Software\eclipse-jee-juno-SR2-win32\eclipse;

            09:07:33,208 INFO  [org.jboss.as.jmx.JMXConnectorService] (MSC service thread 1-7) Starting remote JMX connector

            09:07:33,224 INFO  [org.jboss.as.ee] (Controller Boot Thread) Activating EE subsystem

            09:07:33,302 INFO  [org.jboss.as.remoting] (MSC service thread 1-5) Listening on /127.0.0.1:9999

            09:07:33,333 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-8) Starting Coyote HTTP/1.1 on http-localhost-127.0.0.1-8080

            09:07:33,614 INFO  [org.jboss.as.connector] (MSC service thread 1-5) Starting JCA Subsystem (JBoss IronJacamar 1.0.3.Final)

            09:07:33,755 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) Bound data source [java:jboss/datasources/ExampleDS]

            09:07:34,380 INFO  [org.jboss.as.deployment] (MSC service thread 1-4) Started FileSystemDeploymentService for directory D:\RSP Softwares\jboss-as-web-7.0.2.Final\jboss-as-web-7.0.2.Final\standalone\deployments

            09:07:34,427 INFO  [org.jboss.as.deployment] (DeploymentScanner-threads - 1) Found MeterEJB.jar in deployment directory. To trigger deployment create a file called MeterEJB.jar.dodeploy

            09:07:34,442 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "schedulerEJB.jar"

            09:07:34,520 INFO  [org.jboss.as.jpa] (MSC service thread 1-8) added javax.persistence.api dependency to schedulerEJB.jar

            09:07:34,552 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named AutomaticSchedulerBean in deployment unit deployment "schedulerEJB.jar" are as follows:

             

                java:global/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:app/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:module/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:global/schedulerEJB/AutomaticSchedulerBean

                java:app/schedulerEJB/AutomaticSchedulerBean

                java:module/AutomaticSchedulerBean

             

            09:07:34,802 INFO  [org.jboss.as] (MSC service thread 1-2) JBoss AS 7.0.2.Final "Arc" started in 12141ms - Started 124 of 181 services (57 services are passive or on-demand)

            09:07:34,849 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "schedulerEJB.jar"

            09:09:29,942 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) Stopped deployment schedulerEJB.jar in 10ms

            09:09:29,942 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) Starting deployment of "schedulerEJB.jar"

            09:09:29,974 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) added javax.persistence.api dependency to schedulerEJB.jar

            09:09:29,974 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named AutomaticSchedulerBean in deployment unit deployment "schedulerEJB.jar" are as follows:

             

                java:global/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:app/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:module/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:global/schedulerEJB/AutomaticSchedulerBean

                java:app/schedulerEJB/AutomaticSchedulerBean

                java:module/AutomaticSchedulerBean

             

            09:09:30,052 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Replaced deployment "schedulerEJB.jar" with deployment "schedulerEJB.jar"

            09:16:43,895 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-7) Stopping Coyote HTTP/1.1 on http-localhost-127.0.0.1-8080

            09:16:43,895 INFO  [org.jboss.as.osgi] (MSC service thread 1-6) JBAS011921: Stopping OSGi Framework

            09:18:02,161 INFO  [org.jboss.as.connector.subsystems.datasources] (Controller Boot Thread) Deploying JDBC-compliant driver class org.h2.Driver (version 1.2)

            09:18:02,177 INFO  [org.jboss.as.clustering.infinispan.subsystem] (Controller Boot Thread) Activating Infinispan subsystem.

            09:18:02,270 INFO  [org.jboss.as.naming] (Controller Boot Thread) JBAS011800: Activating Naming Subsystem

            09:18:02,286 INFO  [org.jboss.as.naming] (MSC service thread 1-5) JBAS011802: Starting Naming Service

            09:18:02,286 INFO  [org.jboss.as.osgi] (Controller Boot Thread) JBAS011910: Activating OSGi Subsystem

            09:18:02,302 INFO  [org.jboss.as.security] (Controller Boot Thread) Activating Security Subsystem

            09:18:02,317 INFO  [org.jboss.remoting] (MSC service thread 1-5) JBoss Remoting version 3.2.0.Beta2

            09:18:02,333 INFO  [org.xnio] (MSC service thread 1-5) XNIO Version 3.0.0.Beta3

            09:18:02,349 INFO  [org.xnio.nio] (MSC service thread 1-5) XNIO NIO Implementation Version 3.0.0.Beta3

            09:18:02,677 INFO  [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-5) The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;native;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Windows Imaging\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.6.0_31\bin;D:\RSP Softwares\jboss-as-web-7.0.2.Final\jboss-as-web-7.0.2.Final\bin;C:\Program Files\apache-maven-3.0.5-bin\apache-maven-3.0.5\bin;C:\apache-ant-1.9.1\bin;C:\Documents and Settings\sesa276545\Desktop\Software\eclipse-jee-juno-SR2-win32\eclipse;

            09:18:02,692 INFO  [org.jboss.as.ee] (Controller Boot Thread) Activating EE subsystem

            09:18:02,692 INFO  [org.jboss.as.jmx.JMXConnectorService] (MSC service thread 1-2) Starting remote JMX connector

            09:18:02,692 INFO  [org.jboss.as.remoting] (MSC service thread 1-6) Listening on /127.0.0.1:9999

            09:18:02,739 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-1) Starting Coyote HTTP/1.1 on http-localhost-127.0.0.1-8080

            09:18:02,880 INFO  [org.jboss.as.connector] (MSC service thread 1-3) Starting JCA Subsystem (JBoss IronJacamar 1.0.3.Final)

            09:18:02,895 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) Bound data source [java:jboss/datasources/ExampleDS]

            09:18:03,067 INFO  [org.jboss.as.deployment] (MSC service thread 1-4) Started FileSystemDeploymentService for directory D:\RSP Softwares\jboss-as-web-7.0.2.Final\jboss-as-web-7.0.2.Final\standalone\deployments

            09:18:03,099 INFO  [org.jboss.as] (Controller Boot Thread) JBoss AS 7.0.2.Final "Arc" started in 2516ms - Started 93 of 148 services (55 services are passive or on-demand)

            09:18:13,114 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) Starting deployment of "schedulerEJB.jar"

            09:18:13,270 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) added javax.persistence.api dependency to schedulerEJB.jar

            09:18:13,286 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named AutomaticSchedulerBean in deployment unit deployment "schedulerEJB.jar" are as follows:

             

                java:global/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:app/schedulerEJB/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:module/AutomaticSchedulerBean!test.AutomaticSchedulerBean

                java:global/schedulerEJB/AutomaticSchedulerBean

                java:app/schedulerEJB/AutomaticSchedulerBean

                java:module/AutomaticSchedulerBean

             

            09:18:13,442 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "schedulerEJB.jar"

            • 3. Re: How to create a scheduler in jboss 7
              Stephen Coy Master

              You're right. It doesn't work in 7.0.2.Final.

               

              It does, however, work in 7.1.1.Final (and presumably newer releases as well).

              • 4. Re: How to create a scheduler in jboss 7
                winston sanker Newbie

                Is there any way i can create Automatic schedulers in Jboss.7.0.2 .?

                • 5. Re: How to create a scheduler in jboss 7
                  Stephen Coy Master

                  According to AS7-1158:

                  {quote}AS 7.0 only supports EJB3.1 lite features. EJB3.1 lite doesn't include timerservice functionality. This will be implemented in 7.1 and is being tracked here AS7-474{quote}

                  1 of 1 people found this helpful
                  • 6. Re: How to create a scheduler in jboss 7
                    Wolf-Dieter Fink Master

                    As  Stephen Coy said, no.

                     

                    The AS7.0 was only provided with the web-profile and restricted features. AS7.1 was the first version which supports the full JEE stack.

                    So you need to update to 7.1, I don't see huge problems with that.

                     

                    Oh, overlap