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. }