if (thebb.isDirect())
{
synchronized (itsPool)
{
// use with debug to determine if byteBuffer is already
// in the pool.
boolean refInPool = false;
int bbAddr = 0;
if (debug)
{
// Check to make sure we don't have 'thebb' reference
// already in the pool before adding it.
for (int i = 0; i < itsPool.size() && refInPool == false; i++)
{
ByteBuffer tmpbb = (ByteBuffer)itsPool.get(i);
if (thebb == tmpbb)
{
refInPool = true;
bbAddr = System.identityHashCode(thebb);
}
}
}
// NOTE: The else part of this if will only get called
// if debug = true and refInPool = true, see logic above.
if (refInPool == false || debug == false)
{
// add ByteBuffer back to the pool
itsPool.add(thebb);
}
else // otherwise, log a stack trace with duplicate message
{
String threadName = Thread.currentThread().getName();
Throwable t =
new Throwable(threadName +
": Duplicate ByteBuffer reference (" +
bbAddr + ")");
t.printStackTrace(System.out);
}
}
// decrement the count of ByteBuffers released
// IMPORTANT: Since this counter is used only for information
// purposes, it does not use synchronized access.
itsObjectCounter--;
}
else
{
// ByteBuffer not pooled nor needed
thebb = null;
}