aboutsummaryrefslogtreecommitdiffstats
path: root/tests/features152/synchronization/AroundLock.java
blob: 048fc8cd52aa11732c8b44f683f6a57d1dc1d62a (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
// around advice and lock

public aspect AroundLock {

	String s = "foo";
//	void around(Object f): lock() && args(f) {
//		System.err.println("around(Object) lock: advice running at "+thisJoinPoint.getSourceLocation());
//		proceed(f);
//	}
	
	void around(Object f): lock() && args(f){
		System.err.println("around() lock: advice running at "+thisJoinPoint.getSourceLocation());
		proceed(s);
		proceed(s);
	}

	void around(Object f): unlock() && args(f) {
		System.err.println("around() unlock: advice running at "+thisJoinPoint.getSourceLocation());
		proceed(s);
		proceed(s);
	}
	
	public static void main(String[] args) {
		Foo aFoo = new Foo();
		aFoo.staticM();
		aFoo.nonstaticM();
	}
	
	static class Foo {
		public void nonstaticM() {
			synchronized (this) {
				System.err.println("non-static method running");
			}
		}
		public static void staticM() {
			synchronized (String.class) {
				System.err.println("static method running");
			}
		}
	}
}