4 Replies Latest reply on May 9, 2013 11:12 PM by jaikiran

    Singleton Bean's @Schedule method run multiple times

    jodt

      I have the following bean that is annotated with @Startup @Singleton and has a method annotated that runs every 5 minutes. The issue I have is when the scheduled method is run by jboss it's running it 10 times. I believe this is because in the standalone.xml the timer-service section has the thread-pool of default which has a max-thread-count of 10. What I'd like is for it to run the scheduled method once. I thought that I could change the pool size but if I do that it means I've changed the pool size for all timer-services which I don't want to do. In the end it seems like regardless of the pool size JBoss shouldn't run my scheduled method multiple times especially since its marked as a singleton. Any help or suggestions would be appreciated.

       

       

      @Startup

      @Singleton

      public class MyBean {

       

      @Schedule(second = "*", minute = "*/5", hour = "*", info = "Report every 5 Minutes",persistent = false)

        public void report() {

                //Report info

           }

      }

       

      My standalone.xml has the following configuration for ejb3 subsystem:

      <subsystem xmlns="urn:jboss:domain:ejb3:1.3">

                  <session-bean>

                      <stateless>

                          <bean-instance-pool-ref pool-name="slsb-strict-max-pool"/>

                      </stateless>

                      <stateful default-access-timeout="5000" cache-ref="simple"/>

                      <singleton default-access-timeout="5000"/>

                  </session-bean>

                  <mdb>

                      <resource-adapter-ref resource-adapter-name="hornet-ra.rar"/>

                      <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>

                  </mdb>

                  <pools>

                      <bean-instance-pools>

                          <strict-max-pool name="slsb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>

                          <strict-max-pool name="mdb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>

                          <strict-max-pool name="ecs-listener-mdb-pool" max-pool-size="10" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="SECONDS"/>

                      </bean-instance-pools>

                  </pools>

                  <caches>

                      <cache name="simple" aliases="NoPassivationCache"/>

                      <cache name="passivating" passivation-store-ref="file" aliases="SimpleStatefulCache"/>

                  </caches>

                  <passivation-stores>

                      <file-passivation-store name="file"/>

                  </passivation-stores>

                  <async thread-pool-name="default"/>

                  <timer-service  thread-pool-name="default">

                      <data-store path="timer-service-data" relative-to="jboss.server.data.dir"/>

                  </timer-service>

                  <remote connector-ref="remoting-connector" thread-pool-name="default"/>

                  <thread-pools>

                      <thread-pool name="default">

                          <max-threads count="10"/>

                          <keepalive-time time="100" unit="milliseconds"/>

                      </thread-pool>

                  </thread-pools>

                  <iiop enable-by-default="false" use-qualified-name="false"/>

              </subsystem>

        • 1. Re: Singleton Bean's @Schedule method run multiple times
          sfcoy

          I don't think this has anything to do with the thread pool size.

           

          Is it running 10 times *every* five minutes, or just the first time?

           

          Try stopping the server, deleting the content of standalone/data/timer-service-data and restarting. There may be old timer data lying around.

          • 2. Re: Singleton Bean's @Schedule method run multiple times
            jodt

            So I created a simple test that prints out a count every time the @schedule method is run. It ran the method at the 5 minute interval once every second.

            It appears my @schedule timing is wrong or Jboss isn't runing it properly.

             

            Here's the output:

            07:55:00,007 INFO  [MyBean] (EJB default - 1) Run Count = 1

            07:55:01,001 INFO  [MyBean] (EJB default - 2) Run Count = 2

            07:55:02,001 INFO  [MyBean] (EJB default - 3) Run Count = 3

            07:55:03,001 INFO  [MyBean] (EJB default - 4) Run Count = 4

            07:55:04,002 INFO  [MyBean] (EJB default - 5) Run Count = 5

            07:55:05,001 INFO  [MyBean] (EJB default - 6) Run Count = 6

            07:55:06,001 INFO  [MyBean] (EJB default - 7) Run Count = 7

            07:55:07,001 INFO  [MyBean] (EJB default - 8) Run Count = 8

            07:55:08,001 INFO  [MyBean] (EJB default - 9) Run Count = 9

            07:55:09,000 INFO  [MyBean] (EJB default - 10) Run Count = 10

            07:55:10,000 INFO  [MyBean] (EJB default - 1) Run Count = 11

            07:55:11,001 INFO  [MyBean] (EJB default - 2) Run Count = 12

            07:55:12,000 INFO  [MyBean] (EJB default - 3) Run Count = 13

            07:55:13,000 INFO  [MyBean] (EJB default - 4) Run Count = 14

            07:55:14,002 INFO  [MyBean] (EJB default - 5) Run Count = 15

            07:55:15,001 INFO  [MyBean] (EJB default - 6) Run Count = 16

            07:55:16,000 INFO  [MyBean] (EJB default - 7) Run Count = 17

            07:55:17,000 INFO  [MyBean] (EJB default - 8) Run Count = 18

            07:55:18,001 INFO  [MyBean] (EJB default - 9) Run Count = 19

            07:55:19,000 INFO  [MyBean] (EJB default - 10) Run Count = 20

            07:55:20,000 INFO  [MyBean] (EJB default - 1) Run Count = 21

            07:55:21,000 INFO  [MyBean] (EJB default - 2) Run Count = 22

            07:55:22,000 INFO  [MyBean] (EJB default - 3) Run Count = 23

            07:55:23,000 INFO  [MyBean] (EJB default - 4) Run Count = 24

            07:55:24,001 INFO  [MyBean] (EJB default - 5) Run Count = 25

            07:55:25,000 INFO  [MyBean] (EJB default - 6) Run Count = 26

            07:55:26,000 INFO  [MyBean] (EJB default - 7) Run Count = 27

            07:55:27,000 INFO  [MyBean] (EJB default - 8) Run Count = 28

            07:55:28,000 INFO  [MyBean] (EJB default - 9) Run Count = 29

            07:55:29,000 INFO  [MyBean] (EJB default - 10) Run Count = 30

            07:55:30,000 INFO  [MyBean] (EJB default - 1) Run Count = 31

            07:55:31,001 INFO  [MyBean] (EJB default - 2) Run Count = 32

            07:55:32,001 INFO  [MyBean] (EJB default - 3) Run Count = 33

            07:55:33,000 INFO  [MyBean] (EJB default - 4) Run Count = 34

            07:55:34,001 INFO  [MyBean] (EJB default - 5) Run Count = 35

            07:55:35,000 INFO  [MyBean] (EJB default - 6) Run Count = 36

            07:55:36,000 INFO  [MyBean] (EJB default - 7) Run Count = 37

            07:55:37,000 INFO  [MyBean] (EJB default - 8) Run Count = 38

            07:55:38,001 INFO  [MyBean] (EJB default - 9) Run Count = 39

            07:55:39,000 INFO  [MyBean] (EJB default - 10) Run Count = 40

            07:55:40,002 INFO  [MyBean] (EJB default - 1) Run Count = 41

            07:55:41,000 INFO  [MyBean] (EJB default - 2) Run Count = 42

            07:55:42,000 INFO  [MyBean] (EJB default - 3) Run Count = 43

            07:55:43,000 INFO  [MyBean] (EJB default - 4) Run Count = 44

            07:55:44,001 INFO  [MyBean] (EJB default - 5) Run Count = 45

            07:55:45,000 INFO  [MyBean] (EJB default - 6) Run Count = 46

            07:55:46,000 INFO  [MyBean] (EJB default - 7) Run Count = 47

            07:55:47,000 INFO  [MyBean] (EJB default - 8) Run Count = 48

            07:55:48,000 INFO  [MyBean] (EJB default - 9) Run Count = 49

            07:55:49,000 INFO  [MyBean] (EJB default - 10) Run Count = 50

            07:55:50,002 INFO  [MyBean] (EJB default - 1) Run Count = 51

            07:55:51,001 INFO  [MyBean] (EJB default - 2) Run Count = 52

            07:55:52,001 INFO  [MyBean] (EJB default - 3) Run Count = 53

            07:55:53,000 INFO  [MyBean] (EJB default - 4) Run Count = 54

            07:55:54,001 INFO  [MyBean] (EJB default - 5) Run Count = 55

            07:55:55,000 INFO  [MyBean] (EJB default - 6) Run Count = 56

            07:55:56,000 INFO  [MyBean] (EJB default - 7) Run Count = 57

            07:55:57,000 INFO  [MyBean] (EJB default - 8) Run Count = 58

            07:55:58,000 INFO  [MyBean] (EJB default - 9) Run Count = 59

            07:55:59,000 INFO  [MyBean] (EJB default - 10) Run Count = 60

            • 3. Re: Singleton Bean's @Schedule method run multiple times
              jodt

              So it appears my @Schedule annotation was wrong.I had:  @Schedule(second = "*", minute = "*/5", hour = "*", info = "Report every 5 Minutes",persistent = false) which means run every hour at every 5 minute interval for every second 0-59 of the 5 minute interval . I changed it to: @Schedule(second = "1", minute = "*/5", hour = "*", info = "Report every 5 Minutes",persistent = false) which means run every hour at every 5 minute interval for the first second of the interval.

              • 4. Re: Singleton Bean's @Schedule method run multiple times
                jaikiran

                Jody Schering wrote:

                 

                I changed it to: @Schedule(second = "1", minute = "*/5", hour = "*", info = "Report every 5 Minutes",persistent = false) which means run every hour at every 5 minute interval for the first second of the interval.

                You can even leave out the "second" attribute altogether since, if not specified, then second, minute and hour all default to 0.