You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Kevin Burton <bu...@spinn3r.com> on 2009/01/07 04:00:53 UTC

InterruptedException

Why does ZK throw InterruptedException?
Shouldn't this be a KeeperException instead of a java system exception when
interrupt() is called?

The javadoc just says:

"If the server transaction is interrupted"

If this is a ZK related it should be KeeperException...



-- 
Founder/CEO Spinn3r.com
Location: San Francisco, CA
AIM/YIM: sfburtonator
Skype: burtonator
Work: http://spinn3r.com

Re: InterruptedException

Posted by Kevin Burton <bu...@spinn3r.com>.
I've really wanted  @threadsafe for a while for methods that are safe so
that you can have compiler errors when calling non-threadsafe APIs.
Kevin

On Fri, Jan 9, 2009 at 8:08 AM, Benjamin Reed <br...@yahoo-inc.com> wrote:

> yes, that is a good article. it is actually the one we used to decide about
> the current way of handling InterruptedException. in retrospect it turns out
> to be a nice way to document that a call is blocking.
>
> ben
>
> -----Original Message-----
> From: Thomas.Johnson@Sun.COM [mailto:Thomas.Johnson@Sun.COM]
> Sent: Friday, January 09, 2009 7:56 AM
> To: zookeeper-user@hadoop.apache.org
> Subject: Re: InterruptedException
>
> Kevin Burton wrote:
> > On Thu, Jan 8, 2009 at 3:21 PM, Benjamin Reed <br...@yahoo-inc.com>
> wrote:
> >
> >
> >> InterruptedException is rather tricky because the semantics of
> >> Thread.isInterrupted() is rather vague. specifically, it is unclear why
> >> someone would interrupt a thread. usually Thread.interrupt() is used to
> shut
> >> things down which requires special handing. thus we propagate it. for
> >> example, i'm not clear how you shutdown your poll() method. an easy way
> to
> >> do it would be to use Thread.interrupt().
> >>
> >>
> >
> > so if you just don't have it throw InterruptedException then
> > thread.interrupt can't be used.  It's an API decision really... if you
> don't
> > want people to interrupt then we don't have to throw
> InterruptedException.
> > I don't know many applications that use this in practice... does anyone
> on
> > this list?  I always felt interrupt() was vestigial... notify/wait are
> > somewhat in the same category IMO but at least they are useful.
> >
> >
> See http://www-128.ibm.com/developerworks/java/library/j-jtp05236.html
> for the idiom associated with thread interrupt methods and
> InterruptedException. I will hasten to add that the appropriate use of
> this idiom in various libraries (including in JDK libraries) is
> inconsistent at best and the behavior is in some cases OS dependent. So
> being careful about the use (maybe even stearing clear) of interrupt for
> 'cancelable' operations is probably wise.
> > In my poll method I don't shutdown.... the goal was to have the developer
> do
> > everything in an event API and code that way.
> >
> > Doing things in both sync and async operations is confusing.
> >
> > Kevin
> >
> >
>
>


-- 
Founder/CEO Spinn3r.com
Location: San Francisco, CA
AIM/YIM: sfburtonator
Skype: burtonator
Work: http://spinn3r.com

RE: InterruptedException

Posted by Benjamin Reed <br...@yahoo-inc.com>.
yes, that is a good article. it is actually the one we used to decide about the current way of handling InterruptedException. in retrospect it turns out to be a nice way to document that a call is blocking.

ben

-----Original Message-----
From: Thomas.Johnson@Sun.COM [mailto:Thomas.Johnson@Sun.COM] 
Sent: Friday, January 09, 2009 7:56 AM
To: zookeeper-user@hadoop.apache.org
Subject: Re: InterruptedException

Kevin Burton wrote:
> On Thu, Jan 8, 2009 at 3:21 PM, Benjamin Reed <br...@yahoo-inc.com> wrote:
>
>   
>> InterruptedException is rather tricky because the semantics of
>> Thread.isInterrupted() is rather vague. specifically, it is unclear why
>> someone would interrupt a thread. usually Thread.interrupt() is used to shut
>> things down which requires special handing. thus we propagate it. for
>> example, i'm not clear how you shutdown your poll() method. an easy way to
>> do it would be to use Thread.interrupt().
>>
>>     
>
> so if you just don't have it throw InterruptedException then
> thread.interrupt can't be used.  It's an API decision really... if you don't
> want people to interrupt then we don't have to throw InterruptedException.
> I don't know many applications that use this in practice... does anyone on
> this list?  I always felt interrupt() was vestigial... notify/wait are
> somewhat in the same category IMO but at least they are useful.
>
>   
See http://www-128.ibm.com/developerworks/java/library/j-jtp05236.html 
for the idiom associated with thread interrupt methods and 
InterruptedException. I will hasten to add that the appropriate use of 
this idiom in various libraries (including in JDK libraries) is 
inconsistent at best and the behavior is in some cases OS dependent. So 
being careful about the use (maybe even stearing clear) of interrupt for 
'cancelable' operations is probably wise.
> In my poll method I don't shutdown.... the goal was to have the developer do
> everything in an event API and code that way.
>
> Doing things in both sync and async operations is confusing.
>
> Kevin
>
>   


Re: InterruptedException

Posted by Thomas Vinod Johnson <Th...@Sun.COM>.
Kevin Burton wrote:
> On Thu, Jan 8, 2009 at 3:21 PM, Benjamin Reed <br...@yahoo-inc.com> wrote:
>
>   
>> InterruptedException is rather tricky because the semantics of
>> Thread.isInterrupted() is rather vague. specifically, it is unclear why
>> someone would interrupt a thread. usually Thread.interrupt() is used to shut
>> things down which requires special handing. thus we propagate it. for
>> example, i'm not clear how you shutdown your poll() method. an easy way to
>> do it would be to use Thread.interrupt().
>>
>>     
>
> so if you just don't have it throw InterruptedException then
> thread.interrupt can't be used.  It's an API decision really... if you don't
> want people to interrupt then we don't have to throw InterruptedException.
> I don't know many applications that use this in practice... does anyone on
> this list?  I always felt interrupt() was vestigial... notify/wait are
> somewhat in the same category IMO but at least they are useful.
>
>   
See http://www-128.ibm.com/developerworks/java/library/j-jtp05236.html 
for the idiom associated with thread interrupt methods and 
InterruptedException. I will hasten to add that the appropriate use of 
this idiom in various libraries (including in JDK libraries) is 
inconsistent at best and the behavior is in some cases OS dependent. So 
being careful about the use (maybe even stearing clear) of interrupt for 
'cancelable' operations is probably wise.
> In my poll method I don't shutdown.... the goal was to have the developer do
> everything in an event API and code that way.
>
> Doing things in both sync and async operations is confusing.
>
> Kevin
>
>   


Re: InterruptedException

Posted by Kevin Burton <bu...@spinn3r.com>.
On Thu, Jan 8, 2009 at 3:21 PM, Benjamin Reed <br...@yahoo-inc.com> wrote:

> InterruptedException is rather tricky because the semantics of
> Thread.isInterrupted() is rather vague. specifically, it is unclear why
> someone would interrupt a thread. usually Thread.interrupt() is used to shut
> things down which requires special handing. thus we propagate it. for
> example, i'm not clear how you shutdown your poll() method. an easy way to
> do it would be to use Thread.interrupt().
>

so if you just don't have it throw InterruptedException then
thread.interrupt can't be used.  It's an API decision really... if you don't
want people to interrupt then we don't have to throw InterruptedException.
I don't know many applications that use this in practice... does anyone on
this list?  I always felt interrupt() was vestigial... notify/wait are
somewhat in the same category IMO but at least they are useful.

In my poll method I don't shutdown.... the goal was to have the developer do
everything in an event API and code that way.

Doing things in both sync and async operations is confusing.

Kevin

-- 
Founder/CEO Spinn3r.com
Location: San Francisco, CA
AIM/YIM: sfburtonator
Skype: burtonator
Work: http://spinn3r.com

RE: InterruptedException

Posted by Benjamin Reed <br...@yahoo-inc.com>.
InterruptedException is rather tricky because the semantics of Thread.isInterrupted() is rather vague. specifically, it is unclear why someone would interrupt a thread. usually Thread.interrupt() is used to shut things down which requires special handing. thus we propagate it. for example, i'm not clear how you shutdown your poll() method. an easy way to do it would be to use Thread.interrupt().

ben

-----Original Message-----
From: Mahadev Konar [mailto:mahadev@yahoo-inc.com] 
Sent: Tuesday, January 06, 2009 7:05 PM
To: zookeeper-user@hadoop.apache.org
Subject: Re: InterruptedException

Hi Kevin,
 The interrupt exception would be thrown in case any other thread tries to
interrupt zookeeper threads during a client call (its not really
interrupting the server but interrupting the client threads). Its like any
synchronous operation that waits throwing an interrupted exception if
interrupted by any other thread.

Mahadev

PS: ill try responding to your other emails as well as soon as possible :).


On 1/6/09 7:00 PM, "Kevin Burton" <bu...@spinn3r.com> wrote:

> Why does ZK throw InterruptedException?
> Shouldn't this be a KeeperException instead of a java system exception when
> interrupt() is called?
> 
> The javadoc just says:
> 
> "If the server transaction is interrupted"
> 
> If this is a ZK related it should be KeeperException...
> 
> 


Re: InterruptedException

Posted by Mahadev Konar <ma...@yahoo-inc.com>.
Hi Kevin,
 The interrupt exception would be thrown in case any other thread tries to
interrupt zookeeper threads during a client call (its not really
interrupting the server but interrupting the client threads). Its like any
synchronous operation that waits throwing an interrupted exception if
interrupted by any other thread.

Mahadev

PS: ill try responding to your other emails as well as soon as possible :).


On 1/6/09 7:00 PM, "Kevin Burton" <bu...@spinn3r.com> wrote:

> Why does ZK throw InterruptedException?
> Shouldn't this be a KeeperException instead of a java system exception when
> interrupt() is called?
> 
> The javadoc just says:
> 
> "If the server transaction is interrupted"
> 
> If this is a ZK related it should be KeeperException...
> 
>