summaryrefslogtreecommitdiffstats
path: root/tests/features152/synchronization/Basic3.java
blob: 01c19671504a1e5395b739b2b1a7f8a999a4a5df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Exploring synchronization

aspect WithinAspect {
	before(Object o ): within(Basic3) && this(o) {
		if (thisJoinPoint.getSignature().toString().indexOf("lock(")!=-1) 
			System.err.println("Advice running at "+thisJoinPoint.getSignature()+
								" with this of type "+o.getClass()+" with value "+o);
	}
}

public class Basic3 {
	public static void main(String[] args) {
		Basic3 b = new Basic3();
		
		b.methodWithSyncBlock1();
		b.staticMethodWithSyncBlock1();
		b.methodWithSyncBlock2();
		b.staticMethodWithSyncBlock2();
	}
	
	public void methodWithSyncBlock1() {
		System.err.println("methodWithSyncBlock1");
		synchronized (this) {
		}
	}

	public void staticMethodWithSyncBlock1() {
		System.err.println("staticMethodWithSyncBlock1");
		synchronized (Basic3.class) {
		}
	}
	
	public void methodWithSyncBlock2() {
		System.err.println("methodWithSyncBlock2");
		synchronized (this) {
			int i = 0;
			while (i<100) {
				i++;
			}
		}
	}

	public void staticMethodWithSyncBlock2() {
		System.err.println("staticMethodWithSyncBlock2");
		synchronized (Basic3.class) {
			int i = 0;
			while (i<100) {
				i++;
			}
		}
	}
}