File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help me with Thread Problem" Watch "help me with Thread Problem" New topic

help me with Thread Problem

Pooja Jindal

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);
} }

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

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:
subject: help me with Thread Problem
It's not a secret anymore!