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);

}

[5535 byte] By [power-extremea] at [2007-11-27 9:19:20]
# 1
What do you mean "not getting stable output"? What are you expecting, and what are you getting instead? Be precise.
jverda at 2007-7-12 22:11:28 > top of Java-index,Java Essentials,New To Java...
# 2

well the code is suppose to gove output as....

The producer made a the product Tv 1

The cosumer got the TV 1

The producer made a the product Tv 2

The cosumer got the TV 2

and son on.....

when i run the program in IDE it is not givin this output.. after 2-3iterations the cosumer threads output comes beforer producer thread and when i tried running it without the notifyAll() method it gives correct result.... but just as i use that notifyAll() it gives wrong output like the cosumer consumes product before producer making it!!

When i run the prgoram through command line with notifyAll() it does give rigth output but if i execute it 2-3 simultaneously one after other.. once in a while it does give wriong output.. so is it like ok with thread programs or there is some bug in my program. This is about the command line but in case of IDE it NEVR gives correct result if i use notifyAll() ... but works fine if i dont use notiyAll() or notify().. so please kidnly correct me if something is wrong thank you!!

power-extremea at 2007-7-12 22:11:28 > top of Java-index,Java Essentials,New To Java...
# 3
It's not surprising if I/O comes out of orderT1: produceT2: consumeT2: write "consumed" to outputT1: write "produced" to outputI haven't read your code, though, so it's still possible you're doing something wrong.
jverda at 2007-7-12 22:11:28 > top of Java-index,Java Essentials,New To Java...
# 4
well the output is comin wrong only in case of notifyAll() in IDE not othewiseand in command line its coming correcet WITH notifyAll() as well but if i execute it over and over it does give wrong once!!!PLease would really help if u can review the code once!!
power-extremea at 2007-7-12 22:11:28 > top of Java-index,Java Essentials,New To Java...