You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Kelvin Tan <ke...@relevanz.com> on 2002/01/14 05:33:05 UTC

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. :)


Regards,
Kelvin Tan

Relevanz Pte Ltd
http://www.relevanz.com

180B Bencoolen St.
The Bencoolen, #04-01
S(189648)

Tel: 238 6229
Fax: 337 4417