Java Reference
In-Depth Information
writeable = false;
notify();
}
synchronized char getSharedChar()
{
while (writeable)
try
{
wait();
}
catch (InterruptedException e) {}
writeable = true;
notify();
return c;
}
}
class Producer extends Thread
{
private Shared s;
Producer(Shared s)
{
this.s = s;
}
@Override
public void run()
{
for (char ch = 'A'; ch <= 'Z'; ch++)
{
synchronized(s)
{
s.setSharedChar(ch);
System.out.println(ch+"
produced
by
produ-
cer.");
}
}
}
Search WWH ::




Custom Search