Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Test(){
- lock1 = new ReentrantLock();
- lock2 = new ReentrantLock();
- condition1 = lock1.newCondition();
- condition2 = lock2.newCondition();
- }
- public void function1() {
- lock1.lock();
- .....
- lock1.unlock();
- }
- public void function2() {
- lock2.lock();
- .....
- lock2.unlock();
- }
- public void function3() {
- .....
- }
- public static void main(){
- Test test = new Test();
- for(int i = 0; i < 10;i++){
- WorkerThread workerThread = new WorkerThread(test);
- workerThread.start();
- }
- }
- public class WorkerThread extends Thread {
- private Test test;
- public WorkerThread(Test test) {
- this.test = test;
- }
- @Override
- public void run() {
- while (true) {
- test.function1();
- test.function2();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement