Last active
June 28, 2022 15:22
-
-
Save OMGZui/b2069e934fdffa09d416a9c471cc6763 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SyncThread implements Runnable { | |
@Override | |
public void run() { | |
System.out.println(Thread.currentThread().getName() + "_Sync: " + new SimpleDateFormat("HH:mm:ss").format(new Date())); | |
synchronized (new SyncThread()) { | |
try { | |
System.out.println(Thread.currentThread().getName() + "_Sync_Start: " + new SimpleDateFormat("HH:mm:ss").format(new Date())); | |
Thread.sleep(2000); | |
System.out.println(Thread.currentThread().getName() + "_Sync_End: " + new SimpleDateFormat("HH:mm:ss").format(new Date())); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
F_thread1_Sync: 23:20:55 | |
F_thread2_Sync: 23:20:55 | |
F_thread4_Sync: 23:20:55 | |
F_thread3_Sync: 23:20:55 | |
F_thread1_Sync_Start: 23:20:55 | |
F_thread2_Sync_Start: 23:20:55 | |
F_thread4_Sync_Start: 23:20:55 | |
F_thread3_Sync_Start: 23:20:55 | |
F_thread4_Sync_End: 23:20:57 | |
F_thread1_Sync_End: 23:20:57 | |
F_thread3_Sync_End: 23:20:57 | |
F_thread2_Sync_End: 23:20:57 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment