Created
October 17, 2016 18:49
-
-
Save sbcd90/8df3ba383285dfb8952dd1b57504ad69 to your computer and use it in GitHub Desktop.
wait_&_notify java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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