Full width home advertisement

HTML

Tech News

Ad

  1.  
  2. class AA {
  3.  
  4. static synchronized void a1() {
  5. System.out.println("a1 is executing......");
  6. BB.b2();
  7. }
  8.  
  9. static synchronized void a2() {
  10. System.out.println("a2 is executing......");
  11. }
  12. }
  13.  
  14. class BB {
  15.  
  16. static synchronized void b1() {
  17. System.out.println("b1 is executing......");
  18. AA.a2();
  19. }
  20.  
  21. static synchronized void b2() {
  22. System.out.println("b2 is executing......");
  23. }
  24. }
  25.  
  26. class ThreadA extends Thread {
  27.  
  28. Thread t;
  29.  
  30. ThreadA() {
  31. t = new Thread();
  32. }
  33.  
  34. public void run() {
  35. try {
  36. for (int i = 1; i <= 10; i++) {
  37. AA.a1();
  38. Thread.sleep(50);
  39. }
  40. } catch (Exception e) {
  41. System.out.println(e);
  42. }
  43. }
  44. }
  45.  
  46. class ThreadB extends Thread {
  47.  
  48. Thread t;
  49.  
  50. ThreadB() {
  51. t = new Thread();
  52. }
  53.  
  54. public void run() {
  55. try {
  56. for (int i = 1; i <= 10; i++) {
  57. BB.b1();
  58. Thread.sleep(10);
  59. }
  60. } catch (Exception e) {
  61. System.out.println(e);
  62. }
  63. }
  64. }
  65.  
  66. public class PR30 {
  67.  
  68. public static void main(String args[]) {
  69. try {
  70. ThreadA ta = new ThreadA();
  71. ThreadB tb = new ThreadB();
  72. ta.start();
  73. tb.start();
  74. ta.join();
  75. tb.join();
  76. } catch (Exception e) {
  77. }
  78. }
  79.  
  80. }

No comments:

Post a Comment

Bottom Ad [Post Page]