starting thread inside synchronized block

J

John Davison

If I start a new thread inside a synchronized (object) block, that thread
doesn't inherit the monitor on object, does it?

Thanks!

John Davison
 
T

Tor Iver Wilhelmsen

John Davison said:
If I start a new thread inside a synchronized (object) block, that thread
doesn't inherit the monitor on object, does it?

You misunderstand: Monitors aren't tied to threads but to objects.
Threads "take" and "release" the sync-object's monitor when they enter
or exit synchronized code. So the Thread you create will not be
associated with a monitor until it enters a synchronized block while
running, the two threads are not related. (Except through a
ThreadGroup if you want them to be.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top