aboutsummaryrefslogtreecommitdiff
path: root/usage_examples/SynchronizedExample_post.jpage
blob: 219ab88adfe212eb14a7b7c7c810bbca30010e24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class SynchronizedExample {
	private static final Object $LOCK = new Object[0];
	private final Object $lock = new Object[0];
	private final Object readLock = new Object();
	
	public static void hello() {
		synchronized($LOCK) {
			System.out.println("world");
		}
	}
	
	public int answerToLife() {
		synchronized($lock) {
			return 42;
		}
	}
	
	public void foo() {
		synchronized(readLock) {
			System.out.println("bar");
		}
	}
}