Created
March 8, 2024 06:49
-
-
Save jaimemin/12906afafc13f98f6e8d98817feebbb0 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
public class SynchronizedExample { | |
private final Object lock1 = new Object(); | |
private final Object lock2 = new Object(); | |
public void performTask() { | |
synchronized (lock1) { | |
System.out.println("lock1 획득"); | |
// lock1에 대한 임계 영역 | |
synchronized (lock2) { | |
System.out.println("lock2 획득"); | |
// lock2에 대한 임계 영역 | |
System.out.println("lock2 해제"); | |
} | |
// lock1에 대한 임계 영역 | |
System.out.println("lock1 해제"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment