5 Replies Latest reply on Jun 20, 2006 6:06 AM by Dimitris Andreadis

    How to persist TimedObject across server recycles / ejb rede

    Mark Lybarger Apprentice

      How can I persist a TimedObject across server recycles / ejb redeployments?

      I create a simple slsb which accesses the TimerService to create a timer. ATM, the timer is scheduled every 3 seconds. My bean implements the TimedObject interface, and I can see the ejbTimeout method being called every few seconds. Great.

      Now I still need a few things.

      1. this can probably be done programatically?, but I want to timeout the timer after say 30 minutes or an hour. It's a job that is polling a printer to see if a print job has completed. After X time it can give up.

      2. i can't let the job get "lost" if the server goes down, or if i redeploy the ejb. so far, when i redeploy the ejb, the job stops. when i restart the server, the job stops. any hints how i can achieve this?

        • 1. Re: How to persist TimedObject across server recycles / ejb
          Mark Lybarger Apprentice

          btw, i'm on jboss 4.0.3RC1. will try 4.0.4 when i get a chance later today.

          do i need some special transaction stuff in the dd's? i don't think i even have a jboss-ejb-jar.xml or what ever it it is. just ejb-jar.xml for the slsb. i couldn't find info that dd stuff is needed for timedobject. i'm using xdoclet to generate the ejb-jar.xml and everything else but the implementation.

          • 2. Re: How to persist TimedObject across server recycles / ejb
            Mark Lybarger Apprentice

            i can't seem to edit my previous posts?

            anyway, i tried jboss-4.0.4CR2 i think it's working kinda like i expected. i can start a job by calling the slsb, which as i said, gets the timer service, and creates a timer. it'll be fun to see how easy it is to get 4.0.4CR2 on a production machine :).

            the timer keeps running through server restarts and ejb deploys, which is good. during server restarts (and redeploys too), the timer's Info class seems to be getting reset to the initial values put into it by the slsb like so:

            i have a TimedJobInfo class. This class contains two integers, a runCount, and a maxRuns. It also has a String for the jobId. It is created in the slsb's business method, and passed to the timer.

            In the ejbTimeout method, the runCount is incremented and compared to the maxRuns (is there a better way to specify that the job should stop after X runs)?. runCount is initially set to 1, and i can watch it get incremented through each execution. When I redeply the ejb, the timer continues to execute, but the runCount is back to 1.

            i suppose this is fine, as to me it's better to run the job more times than needed. the purpose of this job is to monitor a print job on another server by making a webservice request to get the status. if the print job has completed (success or fail) it posts xml to another server.

            i'll end with some questions to hopefully get more info from the timedobject/timerservice folks.

            1. should i expect 4.0.3 to persist my job through server restarts out of the box? if not can it be configured to do so?

            2. is there a way to get the job's Info to re-persist it's state after each job execution.


            • 3. Re: How to persist TimedObject across server recycles / ejb
              Roman Newbie

              I have similar problem.
              I used 4.0.3SP1.
              Now I am using jboss-4.0.4GA but the problem is not gone.

              I have tried CR2, but it seems to have different EJB3 in it and my refactored_to_work_with_4.0.4GA application does not work with 4.0.4CR2.

              I observe the same behaviour as it was with 4.0.3SP1: when I create the timer - new item in table 'timers' in database(I use PostgreSQL) arrive, but when server is stopped the item is removed :(
              I am using stateless session bean as TimerService client.

              Should I do some additional configuration or is it a bug?
              There was a alink in 4.0.4GA release notes to the persistence bug and it said to be fixed but I don't think so.

              • 4. Re: How to persist TimedObject across server recycles / ejb
                Roman Newbie

                I tried RC2, RC1 - no result. Timers are deleted from database on server shutdown.

                • 5. Re: How to persist TimedObject across server recycles / ejb
                  Dimitris Andreadis Master

                  About the persistence issue see http://jira.jboss.com/jira/browse/EJBTHREE-630 EJB3 need to be changed to use the new API.

                  About the timerInfo, as far as I remember this is only saved when the timer gets created.