Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class MutexCheckingFramework {
  4.  
  5. public static void main(String[] args) {
  6. //test(new LocklessRunnable());
  7. test(new DekkerLockRunnable(new DekkerLock()));
  8. }
  9.  
  10. private static void test(Runnable runnable) {
  11. int numOfThreads = 2;
  12. ArrayList<Thread> threads = new ArrayList<>();
  13.  
  14. for (int i = 0; i < numOfThreads; i++) {
  15. threads.add(new Thread(runnable));
  16. }
  17.  
  18. for(Thread thread: threads) {
  19. thread.start();
  20. }
  21.  
  22. for(Thread thread: threads) {
  23. try {
  24. thread.join();
  25. } catch (InterruptedException x) {
  26. x.printStackTrace();
  27. }
  28. }
  29.  
  30. System.out.println("----------------------------------------------------");
  31. System.out.println(("Counter: " + DekkerLockRunnable.count));
  32. System.out.println(("Counter: " + LocklessRunnable.counter));
  33. System.out.println("----------------------------------------------------");
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement