Is there anything wrong in this code?
Can somebody please tell me what iam doin wrong in this program as iam not getting a stable output... thank you!!!THis a typical synchronization program or producer consumer .. but i dont know why iam not getting stable and synchronized output... please if any corrections then please kindly correct me thank you!!
The share data class
package produceSupply;
publicclass Data{
private String content;
privateboolean avaliable=false;
synchronizedpublicvoid putContent(String part){
try{
while(avaliable==true){
wait(1000);
}
}catch(InterruptedException ie){
ie.printStackTrace();
}
content=part;
avaliable=true;
notifyAll();
}
synchronizedpublic String getContents(){
try{
while(avaliable==false){
wait(1000);
}
}catch(InterruptedException ie){
ie.printStackTrace();
}
avaliable=false;
return content;
}
}
Producer class
package produceSupply;
publicclass Producerimplements Runnable{
Data data;
Thread t1;
public Producer(Data data){
this.data=data;
t1=new Thread(this);
t1.start();
}
publicvoid run(){
for(int i=1;i<=10;i++){
data.putContent("Tv "+i);
System.out.println("The producer made the Tv product :" +i);
try{
Thread.sleep(50);
}catch(InterruptedException ie){
}
}
}
}
The consumer Class
package produceSupply;
publicclass Consumerimplements Runnable{
Data data;
Thread t2;
public Consumer(Data data){
this.data=data;
t2=new Thread(this);
t2.start();
}
publicvoid run(){
String part="";
for(int i=0;i<10;i++){
part=data.getContents();
System.out.println("The consumer got the: "+ part +"\n");
try{
Thread.sleep(125);
}catch(InterruptedException ie){
ie.printStackTrace();
}
}
}
}
The main class
package produceSupply;
publicclass ProductionLine{
publicstaticvoid main(String[] args){
Data data=new Data();
Producer p1=new Producer(data);
Consumer c1=new Consumer(data);
}

