Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Thread interrupt during Job execution
Thread interrupt during Job execution [message #331874] Fri, 26 September 2008 00:45 Go to next message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
Is there a preferred/best practice way to handle thread interrupts
during an Eclipse Job#run execution?

I know I am advised to periodically poll IProgressMonitor.isCancelled().
But what about Thread.currentThread().isInterrupted()? General Java
practice tells me I should poll this too, but it is cumbersome to deal
with both mechanisms.

Can I make the assumption that my job will not be interrupted using the
thread interrupt flag? If not, maybe there could be some infrastructure
to be able to check both at once?

I know this is fairly esoteric, but appreciate any advice!

-Will
Re: Thread interrupt during Job execution [message #331919 is a reply to message #331874] Mon, 29 September 2008 13:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Java isInterrupted() is used very infrequently and usually only between
threads that know that they will be communicating in that manner.
Typically this is ignored.

As for Jobs, the IProgressMonitor.isCancelled() is the official way to
request that an Eclipse job to stop running. So if you are long running
job you really should be periodically checking this.

I would personally ignore the Thread.isInterrupted checking.


--
Thanks,
Rich Kulp
Re: Thread interrupt during Job execution [message #332069 is a reply to message #331919] Thu, 02 October 2008 02:11 Go to previous message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
Thanks for the response.

The cancellation mechanism has the limitation that it will not have an
affect during things like Thread.sleep() or blocking IO. So in those
situations, you may want to use interruption in addition to the cancel.
Something like:
if (!myJob.cancel()) {
Thread thread = myJob.getThread();
if (thread != null) thread.interrupt();
}

That is assuming the job is not just ignoring InterruptedExceptions
during those long running, blocking operation.

As far as polling isInterrupted(), I guess that is a design decision.

Rich Kulp wrote:
> Java isInterrupted() is used very infrequently and usually only between
> threads that know that they will be communicating in that manner.
> Typically this is ignored.
>
> As for Jobs, the IProgressMonitor.isCancelled() is the official way to
> request that an Eclipse job to stop running. So if you are long running
> job you really should be periodically checking this.
>
> I would personally ignore the Thread.isInterrupted checking.
>
>
Previous Topic:Update Site URL for a feature
Next Topic:automatically reload files without asking me
Goto Forum:
  


Current Time: Sat Jul 20 23:24:57 GMT 2024

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

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

Back to the top