"Kelvin Tan" <[EMAIL PROTECTED]> writes:

> I posted this 2 days back, but it probably went un-noticed in the deluge of
> posts, so here's another shot.
>
> If my corrections are wrong, then it probably means that at least the
> Non-Persistent Scheduler is defective.
>
> ----- Original Message -----
> From: Kelvin Tan <[EMAIL PROTECTED]>
> To: Turbine Users List <[EMAIL PROTECTED]>
> Sent: Monday, January 14, 2002 12:33 PM
> Subject: Documentation for Scheduler Service
>
>
> At
> http://jakarta.apache.org/turbine/turbine-2/services/scheduler-service.html,
> the example given for a sample ScheduledJob is
>
> public class SimpleScheduledTask extends ScheduledJob
> {
>     private int taskcount = 0;
>
>     /**
>      * Constructor
>      */
>      public SimpleScheduledTask()
>      {
>          //do Task initialization here
>      }
>
>
>     /**
>      * Run the Jobentry from the scheduler queue.
>      * From ScheduledJob.
>      *
>      * @param job The job to run.
>      */
>     public void run( JobEntry job ) throws Exception
>     {
>         Log.note("Scheduled job " + job.getId() + " : " +
>                  "task: " + job.getTask() +
>                  " ran @: " +
>                  new Date(System.currentTimeMillis()).toString() +
>                  " taskcount " + taskcount
>                  );
>         //iterate the task counter
>         taskcount++;
>     }
> }
>
> The expected output is the String given with an incrementing taskcount.
> However, in WorkerThread, jobs are actually executed like
>
> ScheduledJob sc = (ScheduledJob) Class.forName(
>                     je.getTask()).newInstance();
>
>                 sc.execute(je);
>
> and new WorkerThreads are instantiated each time a job executes (they are,
> aren't they?). This means that taskcount will never get to increment since
> the variable is re-initialized each time the job runs.
>
> Making taskcount a static variable would be more correct, I think.
> Otherwise, there's another reason why my test case isn't running correctly.

Hi Kelvin.  Even a static won't work as proposed.  Since you have no
hard reference to SimpleScheduledTask it's possible that the class
loader will unload this class if there are ever no instances of it in
the JVM (resetting your counter back to the beginning).

That data needs to be stored somewhere else (i.e. in another class,
etc.).  Will you please send a unidiff
<http://jakarta.apache.org/site/source.html> and send mail like this
to the dev list with your next suggestion?

                             Thanks, Dan

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to