Force job to stop [message #465123] |
Fri, 23 March 2007 09:37 |
Eclipse User |
|
|
|
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 #465137 is a reply to message #465123] |
Fri, 23 March 2007 11:19 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 #465201 is a reply to message #465141] |
Mon, 26 March 2007 11:26 |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03650 seconds