You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AroundLock.java 960B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // around advice and lock
  2. public aspect AroundLock {
  3. String s = "foo";
  4. // void around(Object f): lock() && args(f) {
  5. // System.err.println("around(Object) lock: advice running at "+thisJoinPoint.getSourceLocation());
  6. // proceed(f);
  7. // }
  8. void around(Object f): lock() && args(f){
  9. System.err.println("around() lock: advice running at "+thisJoinPoint.getSourceLocation());
  10. proceed(s);
  11. proceed(s);
  12. }
  13. void around(Object f): unlock() && args(f) {
  14. System.err.println("around() unlock: advice running at "+thisJoinPoint.getSourceLocation());
  15. proceed(s);
  16. proceed(s);
  17. }
  18. public static void main(String[] args) {
  19. Foo aFoo = new Foo();
  20. aFoo.staticM();
  21. aFoo.nonstaticM();
  22. }
  23. static class Foo {
  24. public void nonstaticM() {
  25. synchronized (this) {
  26. System.err.println("non-static method running");
  27. }
  28. }
  29. public static void staticM() {
  30. synchronized (String.class) {
  31. System.err.println("static method running");
  32. }
  33. }
  34. }
  35. }