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
Joined: Dec 15, 2000
Posts: 68
posted
0
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.
Regards<BR>---------<BR>vadiraj<P><BR>*****************<BR>There's a lot of I in J.<BR>*****************