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