简体   繁体   中英

Invoke isAlive() or join()

When I invoke isAlive(), I saw the code form like: m.thrd.isAlive(). m implements runnable interface. thrd is the object of Thread.

I understand isAlive() is the method of Thread class, we use Thrd.isAlive() to invoke. And we need to let it know m is the thread should be die first. But how to understand object.object.method this format?

Thanks in advance

This has nothing not do with multi-threading; this is purely about Java syntax rules and the semantics of the "." in java statements. What you got here is:

a class that has a field m

m than has a field thrd

thrd has a method isAlive().

In other words. m.thrd.isAlive() accesses a field m, to access a field thrd, to access a method isAlive().

Btw: terrible naming - one shouldn't use one letter names for variables, and there is absolutely no point in using an abbreviation like "thrd" either. That just confuses the reader.

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