Skip to content

Instantly share code, notes, and snippets.

@randomstatistic
Created April 29, 2016 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomstatistic/87caefdea8435d6af4ad13a3f92d2698 to your computer and use it in GitHub Desktop.
Save randomstatistic/87caefdea8435d6af4ad13a3f92d2698 to your computer and use it in GitHub Desktop.
FixedBitSet Pooler
public class FixedBitSetPool {
public static final int poolSize = 10;
private static ArrayBlockingQueue<FixedBitSet> pool = new ArrayBlockingQueue<FixedBitSet>(poolSize);
// Ask for a FBS
public static FixedBitSet request(int size) {
FixedBitSet next = pool.poll();
if (next == null || next.length() < size) {
// if the size doesn't match, throw it away and return a new one of the requested size
return new FixedBitSet(size);
}
else {
return next;
}
}
// Offer up a FBS for reuse
public static void recycle(FixedBitSet bs) {
bs.clear(0, bs.length());
pool.offer(bs);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment