Collection Buffer : Collection « Apache Common « Java






Collection Buffer

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








ApacheCollectionBufferExample.zip( 514 k)

Related examples in the same category

1.Collection Bag
2.Transformer Example
3.Collection BidiMap
4.Collection Closure
5.Comparator Example For BuildIn Data Type
6.Comparator Example For User Defined Class
7.Cookie Bag 2
8.Factory Example 1
9.HashMap Example 1
10.List Example 1
11.MapHeaven 1
12.Multi Key Example 1
13.MultiKey Example 2
14.Set Example 1
15.Set Example 2
16.Bean Comparator ( Sorting based on Properties of class )Bean Comparator ( Sorting based on Properties of class )