4 Replies Latest reply on Aug 31, 2007 2:29 PM by sbivol

    EJB initialization

    edwiles

      Hello,

      We have a stateless session bean that encapsulates a job scheduler, with a web service interface to add/remove jobs. There must be only one instance of the job scheduler running in JBoss at any one time.

      1. How can we get the bean to initialize when JBoss starts up? Even if we make the scheduler a static variable, it only constructs when the bean is first accessed by a web service client.

      2. Does JBoss ever use multiple JVMs to run its EJBs? If it does, we cannot make the scheduler a static variable because it may have multiple instances within JBoss. What should we do in that case?

      Many thanks

      Ed

        • 1. Re: EJB initialization
          jaikiran

           

          "edwiles" wrote:

          1. How can we get the bean to initialize when JBoss starts up?


          As far as i know, there isnt a direct way of doing this.

          Have you checked this section in the JBoss guide which mentions about scheduling tasks using JMX http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch10.html#ch10.sched.sect

          • 2. Re: EJB initialization
            darretta

            >> How can we get the bean to initialize when JBoss starts up?

            This may be a non-standard means to doing this, but we added a few servlets on our persistence layer to automatically start up and initialize timer tasks. Maybe this could solve your issue?

            • 3. Re: EJB initialization
              edwiles

              Thanks for the replies. For the scheduler we ended up using a Service POJO bean which is always a singleton. Then we used our existing web service bean simply as an interface into that. Seems to work!

              See http://docs.jboss.org/ejb3/app-server/tutorial/service/service.html

              • 4. Re: EJB initialization
                sbivol

                Did the tutorial work for you?

                I created a service as described in the tutorial, but it is throwing an exception when I shutdown jboss.

                Then I deployed the tutorial applicatoin from the src url specified in the previous post, and it fails again at jboss shutdown. Here are the exceptions on the jboss console:

                2007-08-31 14:17:55,870 WARN [ServiceDelegateWrapper] Stopping failed jboss.j2ee:jar=tutorial.jar,name=ServiceThree,ser
                vice=EJB3
                java.lang.RuntimeException: javax.management.InstanceNotFoundException: jboss.j2ee:jar=tutorial.jar,name=ServiceThree,se
                rvice=EJB3,type=ManagementInterface is not registered.
                ....
                stack trace
                ....
                2007-08-31 14:17:56,308 WARN [ServiceController] Ignoring request to stop nonexistent service: jboss.j2ee:jar=tutorial.
                jar,name=ServiceThree,service=EJB3,type=ManagementInterface
                ServiceTwo - Stopping
                2007-08-31 14:17:56,308 WARN [ServiceDelegateWrapper] Stopping failed jboss.j2ee:jar=tutorial.jar,name=ServiceTwo,servi
                ce=EJB3
                java.lang.RuntimeException: javax.management.InstanceNotFoundException: tutorial:service=serviceTwo is not registered.
                ...
                stack trace
                ...
                followed by same message for ServiceOne.

                Is this a known issue?

                Thanks
                Sergiu