Hey everyone!. I need to get output like in screenshot pinned to this message.
How i can get it from this code? Code:
class MyThreads {
public final static Object den = new Object();
public final static Object ada = new Object();
private static volatile boolean isLocked = true;
public static int n;
public static int m;
public static Thread t1 = new Thread() {
public void run() {
synchronized (den) {
for (int i = 0; i < 5; i++, n++)
System.out.println("Thread1 n = " + n);
Thread.yield();
synchronized (ada) {
ada.notifyAll();
try {
ada.wait();
ada.notifyAll();
} catch (InterruptedException e) {
e.printStackTrace();
}
for (int i = 0; i < 5; i++, m++)
System.out.println("Thread1 m = " + m);
System.out.println("Thread1 success!");
}
}
}
};
public static Thread t2 = new Thread() {
public void run() {
synchronized (ada) {
try {
ada.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
for (int i = 0; i < 5; i++, m++)
System.out.println("Thread2 m = " + m);
Thread.yield();
synchronized (den) {
try {
den.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
for (int i = 0; i < 5; i++, n++)
System.out.println("Thread2 n = " + n);
System.out.println("Thread2 success!");
}
}
}
};
}