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.

LockingWithTJP.java 628B

12345678910111213141516171819202122232425262728
  1. // obtaining the object being locked on
  2. public aspect LockingWithTJP {
  3. before(): lock() {
  4. System.err.println("before() lock: advice running at "+thisJoinPoint.getSourceLocation());
  5. System.err.println("Locked on "+thisJoinPoint.getArgs()[0]);
  6. }
  7. public static void main(String[] args) {
  8. Foo aFoo = new Foo();
  9. aFoo.nonstaticM();
  10. aFoo.staticM();
  11. }
  12. static class Foo {
  13. public void nonstaticM() {
  14. synchronized (this) {
  15. System.err.println("non-static method running");
  16. }
  17. }
  18. public static void staticM() {
  19. synchronized (String.class) {
  20. System.err.println("static method running");
  21. }
  22. }
  23. }
  24. }