Module-4-Multithreading in Java (1)
Module-4-Multithreading in Java (1)
thread.start();
System.out.println("This code is outside of the thread");
}
public void run() {
System.out.println("This code is running in a thread");
}
}
True False
synchronized(object) {
// statements to be synchronized
}
try { Thread.sleep(10); }
catch (InterruptedException e) {System.out.println(“Exception raised");
}
System.out.println("Thread 1: Waiting for lock 2...");
synchronized (Lock2) {
System.out.println("Thread 1: Holding lock 1 & 2...");
}
}
}
}
try {
Thread.sleep(10);
}
catch (InterruptedException e) {
System.out.println(“Exception raised");
}
synchronized (Lock1) {
System.out.println("Thread 2: Holding lock 1 & 2...");
}
}
}
}
}
System.out.println("Thread is Resumed");
try {
t1.join();
}
catch(Exception e)
{
System.out.println(e);
}
}
}