Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Help!!!

 
shalini Rajan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some confusion about the old discussion question
http://www.javaranch.com/ubb/Forum24/HTML/000088.html
Locking is the main mechanism for restricting simultaneous thread access to specific java code. Which of the following statement(s) are true regarding locks / monitors?
a)One lock / monitor is associated with each Class
b)One lock / monitor is associated with each Synchronized block
c)One lock / monitor is associated with each Thread
d)One lock / monitor is associated with each Object
e)All of the above
-----> The some of them from the discussion group concluded that
ans a,d is correct and some a,b,d ..which one is correct?
With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running
-----> some of them suggest b is correct and some c ..which on e is correct?
Shalini
 
vadiraj vd
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shalini Rajan:
I have some confusion about the old discussion question
http://www.javaranch.com/ubb/Forum24/HTML/000088.html
Locking is the main mechanism for restricting simultaneous thread access to specific java code. Which of the following statement(s) are true regarding locks / monitors?
a)One lock / monitor is associated with each Class
b)One lock / monitor is associated with each Synchronized block
c)One lock / monitor is associated with each Thread
d)One lock / monitor is associated with each Object
e)All of the above
-----> The some of them from the discussion group concluded that
ans a,d is correct and some a,b,d ..which one is correct?
With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running
-----> some of them suggest b is correct and some c ..which on e is correct?
Shalini

I think the answers for the first question are : a and d.
and for second question b and e are the correct answers.
If a thread calls a synchronized method of a object/class it obtains the monitor of that object/class. Other threads are not allowed to call this synchronized method or any other synchronized methods of that object/class.
Regarding daemon threads the JVM will shuts down if it sees that no user threads are running.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic