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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Exploring synchronization
  2. aspect WithinAspect {
  3. before(Object o ): within(Basic5) && target(o) {
  4. if (thisJoinPoint.getSignature().toString().indexOf("lock")!=-1)
  5. System.err.println("Advice running at "+thisJoinPoint.getSignature()+
  6. " with target of type "+o.getClass()+" with value "+o);
  7. }
  8. }
  9. public class Basic5 {
  10. public static void main(String[] args) {
  11. Basic5 b = new Basic5();
  12. b.methodWithSyncBlock1();
  13. b.staticMethodWithSyncBlock1();
  14. b.methodWithSyncBlock2();
  15. b.staticMethodWithSyncBlock2();
  16. }
  17. public void methodWithSyncBlock1() {
  18. System.err.println("methodWithSyncBlock1");
  19. synchronized (this) {
  20. }
  21. }
  22. public void staticMethodWithSyncBlock1() {
  23. System.err.println("staticMethodWithSyncBlock1");
  24. synchronized (Basic5.class) {
  25. }
  26. }
  27. public void methodWithSyncBlock2() {
  28. System.err.println("methodWithSyncBlock2");
  29. synchronized (this) {
  30. int i = 0;
  31. while (i<100) {
  32. i++;
  33. }
  34. }
  35. }
  36. public void staticMethodWithSyncBlock2() {
  37. System.err.println("staticMethodWithSyncBlock2");
  38. synchronized (Basic5.class) {
  39. int i = 0;
  40. while (i<100) {
  41. i++;
  42. }
  43. }
  44. }
  45. }