✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
public abstract class SomeClass implements Runnable {
private Object lock = new Object ();
public void lock () {
synchronized (lock) {
try {
lock.wait ();
System.out.print ( "1");
} Catch (InterruptedException e) { }
}
}
public void notifyThread () {
synchronized (lock) {
lock.notify ();
}
}
public void unlock () {
synchronized (lock) {
lock.notify ();
System.out.print ( "2");
}
}
public static void main (String s []) {
Thread t = new Thread (new SomeClass () {
public void run () {
lock ();
try {
Thread.sleep (1000);
} Catch (InterruptedException e) { }
notifyThread ();
}
});
t.start ();
Thread t1 = new Thread (new SomeClass () {
public void run () {
unlock ();
}
});
t1.start ();
}
}
(Java)