SimplePoolpublic final class SimplePool extends Object Simple object pool. Based on ThreadPool and few other classes
The pool will ignore overflow and return null if empty. |
Fields Summary |
---|
private static final int | DEFAULT_SIZE | private Object[] | pool | private int | max | private int | current | private Object | lock |
Constructors Summary |
---|
public SimplePool()
this.max=DEFAULT_SIZE;
this.pool=new Object[max];
this.lock=new Object();
| public SimplePool(int max)
this.max=max;
this.pool=new Object[max];
this.lock=new Object();
|
Methods Summary |
---|
public java.lang.Object | get()Get an object from the pool, null if the pool is empty.
Object item = null;
synchronized( lock ) {
if( current >= 0 ) {
item = pool[current];
current -= 1;
}
}
return item;
| public int | getMax()Return the size of the pool
return max;
| public void | put(java.lang.Object o)Adds the given object to the pool, and does nothing if the pool is full
synchronized( lock ) {
if( current < (max-1) ) {
current += 1;
pool[current] = o;
}
}
|
|