Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. private static LinkedHashSet<BigInteger> locks = new LinkedHashSet<BigInteger>();
  2.     private static final ReentrantLock lock = new ReentrantLock();
  3.     private boolean acquireLock(BigInteger tr)
  4.     {
  5.         lock.lock();
  6.         try{
  7.             if (locks.contains(tr)){
  8.                 return false;
  9.             } else {
  10.                 locks.add(tr);
  11.                 return true;
  12.             }
  13.         }finally
  14.         {
  15.             lock.unlock();
  16.         }
  17.     }
  18.  
  19.     private void releaseLock(BigInteger tr)
  20.     {
  21.         lock.lock();
  22.         try
  23.         {
  24.             locks.remove(tr);
  25.         } finally
  26.         {
  27.             lock.unlock();
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement