I have researched this problem further. Basically the
TurbineSchedulerService is not really suited to being able to intervene in
currently running jobs. Since my application can have jobs that run for a
couple of hours it is very useful to be able to kill them off without having
to stop Tomcat to do it.

It looks like I am going to have to extend (replace) TurbineSchedulerService
to achieve my end. This would involve caching all threads started by
MainLoop in TurbineSchedulerService. The cache would be keyed on
je.toString() and hold a reference to the Thread object. An additional
method in TurbineSchedulerService ( public Thread
getJobEntryThread(je.toString()) ) would allow the user to pass in a
je.toString() argument and have the Thread returned. Then the caller could
use the method interrupt() which would interrupt the WorkerThread which in
turn used ScheduledJobLoader to get an instance of and run the ScheduledJob
object. I assume this means the ScheduledJob is running in that Thread and
will respond to the Thread.isInterrupted() call so we can then go about
shutting the job down gracefully.

Comments, ideas, alternatives?

David
-----Original Message-----
From: David Wynter [mailto:[EMAIL PROTECTED]]
Sent: 24 April 2002 14:07
To: Turbine-User
Subject: How do you stop long running scheduled jobs?


I have a screen that shows an active jobs running as a result of the
TurbineScheduledJob service running them. I have an action as a result of
that screen that returns a list of active jobs I want to terminate. It seems
the best way to do this in Java is Thread.interrupt() them.

So in my action class I have the following code:

                    if(je.isActive()) {

if(aData.getParameters().getString(aSchedule.getScheduleName()) != null) {
                            ScheduledJob
runningjob=ScheduledJobLoader.getInstance().getInstance(je.getTask());
                            // How do I get the Thread that this job is
running in so I can call interrupt()?
                        }
                    }

The job itself has been modified so that the main loop where it does it's
work has:

          try
        {   while( !Thread.interrupted() )
            {
                // Do your work
            }
        }
        catch( InterruptedException e ){/*terminate thread by returning*/}

Any ideas on this or a different way of doing it?

Thanks

David Wynter
Director
roamware Ltd.
(+44) (0) 208 922 7539 B.
(+44) (0) 7879 605 706 M.
[EMAIL PROTECTED]


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


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

Reply via email to