Advertisement
Guest User

Untitled

a guest
Feb 6th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Test {
  4.  
  5. private static final Object LOCK = new Object();
  6.  
  7. public static void main(String[] args) {
  8. final Thread thread = new Thread() {
  9. public void run() {
  10. while (true) {
  11. synchronized (LOCK) {
  12. System.out.println("Looped at: " + System.currentTimeMillis());
  13. try {
  14. LOCK.wait();
  15. } catch (Exception ignored) {
  16. ignored.printStackTrace();
  17. }
  18. }
  19. }
  20. }
  21. };
  22. thread.start();
  23. final Scanner in = new Scanner(System.in);
  24. while (true) {
  25. if (in.nextLine().equals("loop")) {
  26. synchronized (LOCK) {
  27. LOCK.notifyAll();
  28. }
  29. }
  30. }
  31. }
  32.  
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement