wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes help me with Thread Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help me with Thread Problem" Watch "help me with Thread Problem" New topic
Author

help me with Thread Problem

Pooja Jindal
Greenhorn

Joined: Aug 08, 2007
Posts: 10
public class ThreadDemo {
synchronized void a() { actBusy(); }
static synchronized void b() { actBusy(); }
static void actBusy() {
try { Thread.sleep(1000); }
catch (InterruptedException e) {}
}
public static void main(String[] args) {
final ThreadDemo x = new ThreadDemo();
final ThreadDemo y = new ThreadDemo();
Runnable runnable = new Runnable() {
public void run() {
int option = (int) (Math.random() * 4);
switch (option) {
case 0: x.a(); break;
case 1: x.b(); break;
case 2: y.a(); break;
case 3: y.b(); break;
} }
};
Thread thread1 = new Thread(runnable);
Thread thread2 = new Thread(runnable);
thread1.start();
thread2.start();
} }

Which of the following pairs of method invocations could NEVER be executing at the same
time?

Answer is
A , F and H.
How ? Please Explain me with Details
Chinni Bujji
Ranch Hand

Joined: Jan 31, 2007
Posts: 60
what is A,F and H
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help me with Thread Problem