mirror of https://github.com/apache/druid.git
add code to release ByteBuffers
This commit is contained in:
parent
7cd45a6e1f
commit
d4a1752c5d
|
@ -23,6 +23,8 @@ import com.google.common.base.Supplier;
|
|||
import com.metamx.common.logger.Logger;
|
||||
import io.druid.collections.StupidPool;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
|
@ -31,6 +33,29 @@ public class OffheapBufferPool extends StupidPool<ByteBuffer>
|
|||
{
|
||||
private static final Logger log = new Logger(OffheapBufferPool.class);
|
||||
|
||||
private static final Method bufferCleaner;
|
||||
private static final Method clean;
|
||||
|
||||
static {
|
||||
try {
|
||||
bufferCleaner = Class.forName("java.nio.DirectByteBuffer").getMethod("cleaner");
|
||||
bufferCleaner.setAccessible(true);
|
||||
clean = Class.forName("sum.misc.Cleaner").getMethod("clean");
|
||||
clean.setAccessible(true);
|
||||
} catch(ClassNotFoundException | NoSuchMethodException e) {
|
||||
throw new RuntimeException("Unable to access ByteBuffer release methods");
|
||||
}
|
||||
}
|
||||
|
||||
private static void releaseBuffer(ByteBuffer buf) {
|
||||
try {
|
||||
Object cleaner = bufferCleaner.invoke(buf);
|
||||
clean.invoke(cleaner);
|
||||
} catch(IllegalAccessException | InvocationTargetException e) {
|
||||
log.error(e, "Unable to release ByteBuffer");
|
||||
}
|
||||
}
|
||||
|
||||
public OffheapBufferPool(final int computationBufferSize)
|
||||
{
|
||||
super(
|
||||
|
|
Loading…
Reference in New Issue