Advertisement
the_alator

Untitled

May 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. package basic;
  2.  
  3. public class Synchronized {
  4. static Object s1 = new Object();
  5. public static void main(String[] args) {
  6. new Thread(Synchronized::method).start();
  7. new Thread(Synchronized::method).start();
  8. }
  9. public static synchronized void method() {
  10. System.out.println("In method method: " + Thread.currentThread().getName());
  11. synchronized(s1) {
  12. System.out.println("In synchronized (s1): " + Thread.currentThread().getName());
  13. try {
  14. s1.wait();
  15. } catch (InterruptedException e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement