package test;
import common.SharedBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author xissburg
*/
public class SharedBufferTest
{
public static void main(String[] args)
{
final SharedBuffer buffer = new SharedBuffer();
//producer
new Thread(new Runnable() {
public void run()
{
int i=0;
while(true)
{
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(SharedBufferTest.class.getName()).log(Level.SEVERE, null, ex);
}
buffer.set(i++);
}
}
}).start();
//consumer
new Thread(new Runnable() {
public void run()
{
while(true)
{
Object o = null;
try {
o = buffer.get(true);
} catch (InterruptedException ex) {
Logger.getLogger(SharedBufferTest.class.getName()).log(Level.SEVERE, null, ex);
}
if(o != null)
System.out.println(o);
}
}
}).start();
System.out.println("Producer and Consumer threads started");
}
}
|