Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock question" Watch "Mock question" New topic
Author

Mock question

Hemal Mehta
Ranch Hand

Joined: Nov 16, 2000
Posts: 101
Mock question. Can anyone provide the answer
How could you coordinate two threads that execute simultaneously inside synchronized methods of the same object?
Choice 1
use Thread.wait() and Thread.notify()
Choice 2
dynamically control the priorities of the threads within the method
Choice 3
use Thread.sleep()
Choice 4
place the threads in the same ThreadGroup and let the ThreadGroup acquire the object's monitor
Choice 5
use Thread.yield() to switch between threads at set points
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Answer is 1.
When you have two threads and they are using synchronized methods, you are dealing with locks.
1. This is how you lock ( wait() ) and release ( notify() and notifyAll() ) locks
2. Some systems will allow this to work, but time-slicing systems won't. They allow threads of lower priority to kick in every now and then. So this won't work on Windows for example.
3. sleep() doesn't release locks.
4. Don't know much about ThreadGroups, but I am fairly sure they don't deal with locks.
5. yield() doesn't release locks.
Bill
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
I think threadgroups can deal with locks?. Any help?

Sun Certified Programmer for Java 2 Platform
Anshuman Acharya
Ranch Hand

Joined: Jan 19, 2001
Posts: 144
the problem bill with answer 1 is that wait() and notify() are NOT static methods of the Thread class!
where idd you get this question from, hemal?
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
I doubt that ThreadGroup deals with locks , because it's like a collection of them which works with in it. SO the the threads that are in it are responsible for locks not ThreadGroup.


Val SCJP <BR>going for SCJD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock question
 
Similar Threads
Demon ThreadGroup/ThreadGroup
threads
Six java questions: Could anyone answer
Centralized catch for all threads
Duplicate thread-id?