Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Force job to stop
Force job to stop [message #465123] Fri, 23 March 2007 09:37 Go to next message
Eclipse UserFriend
Originally posted by: johan.geodan.nl

Within my application i use some background jobs to collect data. When closing my application i cancel all the job and then do a join to wait when all jobs are cancel.

This was working perfect but now i find out a problem with a job that is executing a method which takes a long time (for example 15 minutes to get response). Of course i should redesign the method but it could always happen for some reason that a method is executing for a long time because of the lack of resources.

Within my job i can check after every method if the job is cancelled. But now i only have one method which take a undefined time to execute. Cancelling is not working in this way.

What is the best way to deal with the problems? Using seperate thread inside the job which can be killed by the job? Or do you have a better idea. Hopefully you can give me some ideas how to implement this issue.
Re: Force job to stop [message #465133 is a reply to message #465123] Fri, 23 March 2007 11:15 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
Code executing inside a job is supposed to check whether it's cancelled or not:

if (monitor.isCanceled()) return Status.CANCEL_STATUS;


It should do that periodically in the processing. It's probably that your method is not doing this at an appropriate point.

There's an article on the jobs API at:

http://www.eclipse.org/articles/Article-Concurrency/jobs-api .html

Alex.
Re: Force job to stop [message #465137 is a reply to message #465123] Fri, 23 March 2007 11:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

On Fri, 23 Mar 2007 05:37:28 -0400, Johan de Koning wrote:

> Within my application i use some background jobs to collect data. When closing my application i cancel all the job and then do a join to wait when all jobs are cancel.
>
> This was working perfect but now i find out a problem with a job that is executing a method which takes a long time (for example 15 minutes to get response). Of course i should redesign the method but it could always happen for some reason that a method is executing for a long time because of the lack of resources.
>
> Within my job i can check after every method if the job is cancelled. But now i only have one method which take a undefined time to execute. Cancelling is not working in this way.
>
> What is the best way to deal with the problems? Using seperate thread inside the job which can be killed by the job? Or do you have a better idea. Hopefully you can give me some ideas how to implement this issue.


Is there no 'interrupt' method? Most blocking calls are created to
respect interruption. I think.
Re: Force job to stop [message #465141 is a reply to message #465133] Fri, 23 March 2007 12:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: johan.geodan.nl

But i mean what if a method inside the job takes a long time to finish. So you get something like this

* Check job cancelled
* Get huge data from the database
* Check job cancelled

The huge data from the database method executed a query on the server which takes a long time. Of course i should consider if i want to use this query but this is not the point now. It could also be possible that it is a query which takes less time but the server resources are all busy so the query execution is taking a long time.

I close the application when the huge data collection method is executed. Now the application is closed but the job is still running in the java environment. How should i cancel this job with interrupting this huge data collection method.

Should i for example create another thread? Or are there better solutions
Re: Force job to stop [message #465143 is a reply to message #465141] Fri, 23 March 2007 12:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Christian.chh.Hinrichs.informatik.uni-oldenburg.de

Johan de Koning schrieb:
> But i mean what if a method inside the job takes a long time to finish. So you get something like this
>
> * Check job cancelled
> * Get huge data from the database
> * Check job cancelled
>
> The huge data from the database method executed a query on the server which takes a long time. Of course i should consider if i want to use this query but this is not the point now. It could also be possible that it is a query which takes less time but the server resources are all busy so the query execution is taking a long time.
>
> I close the application when the huge data collection method is executed. Now the application is closed but the job is still running in the java environment. How should i cancel this job with interrupting this huge data collection method.
>
> Should i for example create another thread? Or are there better solutions

I think creating a thread would be the best solution. So that your
long-time-method runs in an own thread, surrounded by your job which
sleeps until the thread has finished but periodically awakes and checks
for cancellation.

Chh
Re: Force job to stop [message #465147 is a reply to message #465141] Fri, 23 March 2007 13:07 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
If you can get hold of the Thread (which I'm not sure you can) you might be able to send it an interrupt to try and bring it down.

I guess the only other approach would be for your Job to spawn a different Thread and have the long-running query running inside that, and then have the Job periodically monitor it.

Alex
Re: Force job to stop [message #465201 is a reply to message #465141] Mon, 26 March 2007 11:26 Go to previous message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

On Fri, 23 Mar 2007 08:29:31 -0400, Johan de Koning wrote:

> But i mean what if a method inside the job takes a long time to finish.
> So you get something like this
>
> * Check job cancelled
> * Get huge data from the database
> * Check job cancelled
>
> The huge data from the database method executed a query on the server
> which takes a long time. Of course i should consider if i want to use
> this query but this is not the point now. It could also be possible that
> it is a query which takes less time but the server resources are all
> busy so the query execution is taking a long time.
>
> I close the application when the huge data collection method is
> executed. Now the application is closed but the job is still running in
> the java environment. How should i cancel this job with interrupting
> this huge data collection method.
>
> Should i for example create another thread? Or are there better
> solutions

At this point it seems you want to cancel something that was not designed
to be canceled. The proper answer is to modify your get data from
database method into something that can be canceled. Politely. And if
that is not possible then for me standard practice is to encapsulate it
inside a thread that you can call 'interrupt' on when you want to cancel.
But again, all methods are not interruptable. check the method call and
see if it throws interruptedException. One in the chain probably does.
Essentially interrupting a thread is the same as canceling a job, the
thread must check for the interruption. some calls do this natively.
Previous Topic:About virtual node on CommonNavigator
Next Topic:Adding a panel?
Goto Forum:
  


Current Time: Mon Sep 16 19:21:32 GMT 2024

Powered by FUDForum. Page generated in 0.03650 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top