Guest User

Untitled

a guest
Nov 15th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. final class WaitTest2 {
  2.  
  3. public static void main(String[] args) {
  4. new WaitTest2().run();
  5. }
  6.  
  7. void run() {
  8. class Closure {
  9. private final Runnable runnable;
  10.  
  11. public Closure(Runnable runnable) {
  12. this.runnable = runnable;
  13. }
  14.  
  15. void call() {
  16. runnable.run();
  17. }
  18. }
  19.  
  20. Closure closure = new Closure(() -> {
  21. try {
  22. wait(1000);
  23. System.out.println("AHA!");
  24. } catch (InterruptedException e) {
  25. throw new RuntimeException(e);
  26. }
  27. });
  28. synchronized (this) {
  29. closure.call();
  30. }
  31. }
  32. }
Add Comment
Please, Sign In to add comment