0

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Understood, obj thrd was created in m's class
If my answer was helpful, please consider accepting it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.