示例#1
0
 private static void lockAndExecute(final Runnable runnable, final Iterator<Guardian> guardians) {
   if (guardians.hasNext()) {
     final Guardian guardian = guardians.next();
     ThreadUtils.log("Acquire lock: %s", guardian);
     synchronized (guardian) {
       ThreadUtils.log("Lock: %s acquired", guardian);
       Guardian.lockAndExecute(runnable, guardians);
     }
     ThreadUtils.log("Release lock: %s", guardian);
   } else {
     ThreadUtils.log("All locks are acquired.  Execute task");
     runnable.run();
   }
 }
示例#2
0
 public static void lockAndExecute(final Runnable runnable, final List<Guardian> guardians) {
   final List<Guardian> orderedGuardians = new ArrayList<>(guardians);
   Collections.sort(orderedGuardians);
   Guardian.lockAndExecute(runnable, orderedGuardians.iterator());
 }
示例#3
0
 public static void lockAndExecute(final Runnable runnable, final Guardian... guardians) {
   Guardian.lockAndExecute(runnable, Arrays.asList(guardians));
 }