Esempio n. 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();
   }
 }
Esempio n. 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());
 }
Esempio n. 3
0
 public static void lockAndExecute(final Runnable runnable, final Guardian... guardians) {
   Guardian.lockAndExecute(runnable, Arrays.asList(guardians));
 }