반응형
import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.buffer.BlockingBuffer;
import org.apache.commons.collections.buffer.PriorityBuffer;
public class BufferExample {
public static void main(String args[]) {
Buffer buffer = new PriorityBuffer();
buffer.add("2");
buffer.add("1");
buffer = BlockingBuffer.decorate(buffer);
buffer.remove();
System.err.println(buffer);
buffer.clear();
AddElementThread runner = new AddElementThread(buffer);
runner.start();
buffer.remove();
System.err.println(buffer);
}
}
class AddElementThread extends Thread {
private Buffer buffer;
public AddElementThread(Buffer buffer) {
this.buffer = buffer;
}
public void run() {
try {
sleep(2000);
} catch (InterruptedException ie) {}
buffer.add("3");
}
}
import org.apache.commons.collections.buffer.BlockingBuffer;
import org.apache.commons.collections.buffer.PriorityBuffer;
public class BufferExample {
public static void main(String args[]) {
Buffer buffer = new PriorityBuffer();
buffer.add("2");
buffer.add("1");
buffer = BlockingBuffer.decorate(buffer);
buffer.remove();
System.err.println(buffer);
buffer.clear();
AddElementThread runner = new AddElementThread(buffer);
runner.start();
buffer.remove();
System.err.println(buffer);
}
}
class AddElementThread extends Thread {
private Buffer buffer;
public AddElementThread(Buffer buffer) {
this.buffer = buffer;
}
public void run() {
try {
sleep(2000);
} catch (InterruptedException ie) {}
buffer.add("3");
}
}