Professional Documents
Culture Documents
HashSet;
import java.util.Scanner;
import java.util.concurrent.Semaphore;
int f1count;
int f2count;
int maxDifference = 0;
/**
* Metod koj treba da gi inicijalizira vrednostite na semaforite i
* ostanatite promenlivi za sinhronizacija.
*
*/
Semaphore f1;
Semaphore f2;
Object obj;
maxDifference=count;
f1=new Semaphore(maxDifference);
f2=new Semaphore(15);
obj=new Object();
}
f1.acquire();
synchronized (obj) {
f1();
}
f2.release();
@Override
public void run() {
try {
executeF1();
} catch (Exception e) {
e.printStackTrace();
}
}
}
f2.acquire();
synchronized (obj) {
f2();
}
f1.release();
@Override
public void run() {
try {
executeF2();
} catch (Exception e) {
e.printStackTrace();
}
}
}