aboutsummaryrefslogtreecommitdiffstats
path: root/tests/features152/synchronization/LockingWithTJP.java
blob: a07b567ce6fe10ad4b66673f474468c03e9792f1 (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
// obtaining the object being locked on

public aspect LockingWithTJP {

	before(): lock() {
		System.err.println("before() lock: advice running at "+thisJoinPoint.getSourceLocation());
		System.err.println("Locked on "+thisJoinPoint.getArgs()[0]);
	}
	
	public static void main(String[] args) {
		Foo aFoo = new Foo();
		aFoo.nonstaticM();
		aFoo.staticM();
	}
	
	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");
			}
		}
	}
}