primeniti synchronized na statickoj promenljivoj neke klase,
i da li je moguce da se dva thread-a sinhronizuju na staticki clan koji je u sastavu neke od njih?
tj da li mogu da napisem:
Code:
class P extend Thread{
public static ls;
public void run(){
while(true){
synchronized(P.ls) {
.................
P.ls.notiffyAll(); <-----
}
}
}
class D extends Thread{
public void run(){
while (true){
synchronized(P.ls){
while (P.ls ne ispuni neki uslov)
P.ls.wait();
.....................
}
}
}
class P extend Thread{
public static ls;
public void run(){
while(true){
synchronized(P.ls) {
.................
P.ls.notiffyAll(); <-----
}
}
}
class D extends Thread{
public void run(){
while (true){
synchronized(P.ls){
while (P.ls ne ispuni neki uslov)
P.ls.wait();
.....................
}
}
}
Mislim, kompajler ne prijavljuje gresku, ali mi se cini da zbog toga
imam problem posle sa izuzetkom "current thread not owner" na liniji notiffyAll(ls) u nekoj
implementaciji ovoga.
hvala.
--------------------
mightymv
mightymv