Пример #1
0
 public void first() {
   try {
     ThreadUtils.sleep(5000);
     System.out.println("first");
     sem1.release();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #2
0
  public void third() {
    try {
      sem2.acquire();
      sem2.release();

      ThreadUtils.sleep(1000);
      System.out.println("third");

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #3
0
  public void second() {
    try {
      sem1.acquire(); // since the CF alreay holds the sem1, this has to be wait
      sem1.release();

      ThreadUtils.sleep(3000);
      System.out.println("second");

      sem2.release();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }