thread interrupt

I was having a discussion with a coworker on what does "owner of the thread" mean in the statement"A thread should be interrupted only by its owner"Is it the class which starts the thread or else.
[217 byte] By [kilyasa] at [2007-10-3 5:00:31]
# 1
> Is it the class which starts the thread Yes. I think so.
cotton.ma at 2007-7-14 23:06:02 > top of Java-index,Java Essentials,Java Programming...
# 2
I would take it as the class that started that thread, but a bit of context might help.
jverda at 2007-7-14 23:06:02 > top of Java-index,Java Essentials,Java Programming...
# 3

> I would take it as the class that started that

> thread, but a bit of context might help.

thats what I thought, however the argument I came across was that anybody who owns an instance of that Thread, or has it passed to it would be the owner of the thread during that period of execution.

Its basically from a perspective that who should and who should not interrupt a Thread

kilyasa at 2007-7-14 23:06:02 > top of Java-index,Java Essentials,Java Programming...
# 4

> > I would take it as the class that started that

> > thread, but a bit of context might help.

>

> thats what I thought, however the argument I came

> across was that anybody who owns an instance of that

> Thread, or has it passed to it would be the owner of

> the thread during that period of execution.

>

> Its basically from a perspective that who should and

> who should not interrupt a Thread

But in that case it's anyone really.

I think the statement makes a valid point. Throwing interrupts in various places in your code is quick ticket to code hell.

But like rules it really should be applyed where appropriate. There are very few hard and fast rules I think. But you have to be sensible in your approach and realize that 99& of the time you should do X or avoid doing X as the case may be.

For this particular rule I would say yes I agree. Only the class starting the thread should interrupt the thread. Doing otherwise probably indicates a design flaw.

cotton.ma at 2007-7-14 23:06:02 > top of Java-index,Java Essentials,Java Programming...
# 5

> > > I would take it as the class that started that

> > > thread, but a bit of context might help.

> >

> > thats what I thought, however the argument I came

> > across was that anybody who owns an instance of

> that

> > Thread, or has it passed to it would be the owner

> of

> > the thread during that period of execution.

> >

> > Its basically from a perspective that who should

> and

> > who should not interrupt a Thread

>

> But in that case it's anyone really.

>

> I think the statement makes a valid point. Throwing

> interrupts in various places in your code is quick

> ticket to code hell.

>

> But like rules it really should be applyed where

> appropriate. There are very few hard and fast rules I

> think. But you have to be sensible in your approach

> and realize that 99& of the time you should do X or

> avoid doing X as the case may be.

>

> For this particular rule I would say yes I agree.

> Only the class starting the thread should interrupt

> the thread. Doing otherwise probably indicates a

> design flaw.

Agreed. another thing that came under discussion in the same context is that whenever an InteruptedException is thrown if it is not passed up the stack and caught it should reset the interrupt status. I have not been able to convince peers on that as well.

Thread.currentThread().interrupt();

Now what could be the pitfalls of not doing that, for most of the code I see floating around doesnot do that either.

kilyasa at 2007-7-14 23:06:02 > top of Java-index,Java Essentials,Java Programming...