Created
April 29, 2016 15:48
-
-
Save randomstatistic/87caefdea8435d6af4ad13a3f92d2698 to your computer and use it in GitHub Desktop.
FixedBitSet Pooler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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