Hi,
I know that when sleep() is executed it does not release the lock.But in under written code this is not the case.
Anyone who can explain it.
-----------------------------------------------
class Text{
public void writeText(){
System.out.println("Text written by Producer");
}
public void readText(){
System.out.println("Text read by Consumer");
}
}
class Producer extends Thread{
Text tx;
Producer( Text tx ){
this.tx=tx;
start();
}
public void run(){
synchronized(tx){
for(int i=0;i<5;i++){
tx.writeText();
try{
sleep(10*1000);
}catch(InterruptedException e){System.out.println("producer interrupted");}
}
}
}
}
class Consumer extends
Thread {
Text tx;
Consumer( Text tx ){
this.tx=tx;
start();
}
public void run(){
synchronized(tx){
for(int i=0;i<5;i++){
tx.readText();
try{
sleep(10*1000);
}catch(Exception e){System.out.println("interrupted");}
}
}
}
}
Thanx in @dvance.
Annie.