Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public Test(){
  2. lock1 = new ReentrantLock();
  3. lock2 = new ReentrantLock();
  4. condition1 = lock1.newCondition();
  5. condition2 = lock2.newCondition();
  6. }
  7.  
  8. public void function1() {
  9. lock1.lock();
  10. .....
  11. lock1.unlock();
  12. }
  13.  
  14. public void function2() {
  15. lock2.lock();
  16. .....
  17. lock2.unlock();
  18. }
  19.  
  20. public void function3() {
  21.  
  22. .....
  23.  
  24. }
  25.  
  26. public static void main(){
  27. Test test = new Test();
  28. for(int i = 0; i < 10;i++){
  29. WorkerThread workerThread = new WorkerThread(test);
  30. workerThread.start();
  31. }
  32. }
  33.  
  34. public class WorkerThread extends Thread {
  35.  
  36. private Test test;
  37.  
  38. public WorkerThread(Test test) {
  39. this.test = test;
  40. }
  41.  
  42. @Override
  43. public void run() {
  44. while (true) {
  45. test.function1();
  46. test.function2();
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement