简体   繁体   中英

How are timeout blocking calls implemented inside Java classes like Socket

There are many APIs in Java that support blockingcall(timeout) like Socket, Lock and others. How are these things implemented in Java?

I tried to find out but it lead to native code which is not visible :(

Is similar approach like creating a thread and interrupting it on timeout are used in java at native level? If so then same could have been done at Java level, why use native?

it lead to native code which is not visible This usually means it not implemented in Java. Usually it is implemented by the OS. You can gett he source for Linux, but not Windows AFAIK.

Using Java Thread interrupt, doesn't actually interrupt the thread. It just sets a flag which doesn't wake all blocking operations. This mechanism is not used as it isn't always what you want.

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