File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock question

 
Hemal Mehta
Ranch Hand
Posts: 101
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1070
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think threadgroups can deal with locks?. Any help?
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 439
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic