選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BeforeLock.java 684B

12345678910111213141516171819202122232425262728293031
  1. // before advice and lock
  2. public aspect BeforeLock {
  3. before(Foo f): lock() && this(f) {
  4. System.err.println("before(Foo) lock: advice running at "+thisJoinPoint.getSourceLocation());
  5. }
  6. before(): lock() {
  7. System.err.println("before() lock: advice running at "+thisJoinPoint.getSourceLocation());
  8. }
  9. public static void main(String[] args) {
  10. Foo aFoo = new Foo();
  11. aFoo.staticM();
  12. aFoo.nonstaticM();
  13. }
  14. static class Foo {
  15. public void nonstaticM() {
  16. synchronized (this) {
  17. System.err.println("non-static method running");
  18. }
  19. }
  20. public static void staticM() {
  21. synchronized (String.class) {
  22. System.err.println("static method running");
  23. }
  24. }
  25. }
  26. }