Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Test {
- private static final Object LOCK = new Object();
- public static void main(String[] args) {
- final Thread thread = new Thread() {
- public void run() {
- while (true) {
- synchronized (LOCK) {
- System.out.println("Looped at: " + System.currentTimeMillis());
- try {
- LOCK.wait();
- } catch (Exception ignored) {
- ignored.printStackTrace();
- }
- }
- }
- }
- };
- thread.start();
- final Scanner in = new Scanner(System.in);
- while (true) {
- if (in.nextLine().equals("loop")) {
- synchronized (LOCK) {
- LOCK.notifyAll();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement