daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Dec 9th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class DekkerLockRunnable implements Runnable {
  2.     public static int count = 0;
  3.     //private static final DekkerLock dekkerLock;
  4.     private DekkerLock dekkerLock;
  5.     /*static {
  6.         dekkerLock = new DekkerLock();
  7.     }*/
  8.  
  9.     public DekkerLockRunnable(DekkerLock lock) {
  10.         System.out.println("Creating new thread...");
  11.         dekkerLock = lock;
  12.     }
  13.  
  14.     @Override
  15.     public void run() {
  16.         //dekkerLock.register();
  17.  
  18.         for (int i = 0; i < 100; i++) {
  19.             dekkerLock.lock();
  20.             System.out.println("Locked thread: " + Thread.currentThread().getName());
  21.             ++count;
  22.             System.out.println("Unlocked thread: " + Thread.currentThread().getName());
  23.             dekkerLock.unlock();
  24.         }
  25.         //dekkerLock.unregister();
  26.     }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top