Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Thread interrupt during Job execution
Thread interrupt during Job execution [message #331874] Thu, 25 September 2008 20:45 Go to next message
Eclipse UserFriend
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 09: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] Wed, 01 October 2008 22:11 Go to previous message
Eclipse UserFriend
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: Thu May 01 12:08:01 EDT 2025

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

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

Back to the top