Skip to content

Instantly share code, notes, and snippets.

@sbcd90
Created October 17, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbcd90/8df3ba383285dfb8952dd1b57504ad69 to your computer and use it in GitHub Desktop.
Save sbcd90/8df3ba383285dfb8952dd1b57504ad69 to your computer and use it in GitHub Desktop.
wait_&_notify java
package com.sap.java;
public class WaitLockTestApp {
private static int sum = 0;
public static void main(String[] args) throws InterruptedException {
final WaitLockTestApp app = new WaitLockTestApp();
Thread thread1 = new Thread(new Runnable() {
public void run() {
synchronized (this) {
for (int i = 0;i < 100; i++) {
sum = sum + i;
}
this.notify();
}
}
});
thread1.start();
synchronized (thread1) {
thread1.wait();
}
System.out.println(sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment