harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jimmy, Jing Lv" <firep...@gmail.com>
Subject Re: [Fwd: [classlib][NIO|VMI]Interruptible channel implementation - how to interact with Thread?]
Date Thu, 15 Jun 2006 02:15:32 GMT
Archie Cobbs wrote:
> Paulex Yang wrote:
>> Seems Thread's implementation must be aware of what operation it is 
>> blocking on. So I propose the following solution:
> 
> I don't think the VM or java.lang.Thread needs to be involved.
> First of all, the code performing the blocking operation knows
> what kind of operation it is, so when it wakes up abnormally it
> can take the appropriate action. This code doesn't necessarily
> reside in java.lang.Thread.
> 
> In Classpath the java.nio stuff is all implemented in native
> libraries without the VM or java.lang.Thread being specially
> "aware" of anything. However, classlib's design may be different
> enough to need it (I haven't studied it as much as you guys).
> 
> E.g., the java.nio native code does invoke Thread.interrupt() and
> Thread.interrupted(), but these are normal, API-specified methods.
> 
> Might be worth taking a look for some design ideas.
> 

Thanks Archie, it sounds interesting :).
As I study few about Classpath, I still have a question here. As we 
know, there are three states of "blocking" on a thread. One is wait(), 
sleep() and so forth, thread class handle them itself, it is easy to 
interrupt; and one is blocking on I/O, invoke Thread.interrupt() may be 
not enough as it is blocked on a system call, e.g., call read on socket 
may not return until it receive something or it is closed. In this way, 
the Thread.interrupt should know how to close the socket to perform the 
real interruption. The question is: how can the thread know if it is 
blocked on wait() or I/O operation currently? I think this is the reason 
why Paulex require Thread to be involved. So I'm very interested in what 
does Classpath do here to stop I/O operation without get involved?

Here is the spec about Thread.interrupt():

"
...
If this thread is blocked in an invocation of the wait(), wait(long), or 
wait(long, int) methods of the Object  class, or of the join(), 
join(long), join(long, int), sleep(long), or sleep(long, int), methods 
of this class, then its interrupt status will be cleared and it will 
receive an InterruptedException.
If this thread is blocked in an I/O operation upon an interruptible 
channel then the channel will be closed, the thread's interrupt status 
will be set, and the thread will receive a ClosedByInterruptException.
...
"

> -Archie
> 
> __________________________________________________________________________
> Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com
> 
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> 
> 


-- 

Best Regards!

Jimmy, Jing Lv
China Software Development Lab, IBM

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message