简体   繁体   中英

How does Thread.interrupted() work in java?

Thread.interrupted() is static method. Then how it is able to modify the interrupted flag of instance objects?


This question is not duplicate of

because they don't address the question mentioned in the description of this post.

Modulo some details, it looks like you could write your own Thread.interrupted() as essentially:

static boolean interrupted ( ) {
    Thread me = Thread.currentThread();
    return me.isInterrupted();
}

So the real question is how does the static function Thread.currentThread() find the current thread? This appears to be a bit of an unsolved mystery: How does Thread.currentThread() work? :) Serious answer: it's specific to the JVM and how threads are implemented.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM