Last active
June 28, 2022 15:24
-
-
Save OMGZui/4907bc78273361f44163b57d827f84f0 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 (this) { | |
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:23:56 | |
F_thread2_Sync: 23:23:56 | |
F_thread3_Sync: 23:23:56 | |
F_thread1_Sync_Start: 23:23:56 | |
F_thread4_Sync: 23:23:56 | |
F_thread2_Sync_Start: 23:23:56 | |
F_thread3_Sync_Start: 23:23:56 | |
F_thread1_Sync_End: 23:23:58 | |
F_thread2_Sync_End: 23:23:58 | |
F_thread3_Sync_End: 23:23:58 | |
F_thread4_Sync_Start: 23:23:58 | |
F_thread4_Sync_End: 23:24:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment