New posts
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
|
||||
/** A real third-party library that uses Unsafe: allocate one direct Netty buffer and use it. Compile and run with netty-common + netty-buffer on the class path. */
|
||||
public class NettyProbe {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("netty sees Unsafe: " + PlatformDependent.hasUnsafe());
|
||||
ByteBuf buf = UnpooledByteBufAllocator.DEFAULT.directBuffer(16);
|
||||
buf.writeLong(0xCAFEBABEL);
|
||||
System.out.println("direct=" + buf.isDirect() + " hasMemoryAddress=" + buf.hasMemoryAddress() + " readLong=" + Long.toHexString(buf.readLong()));
|
||||
buf.release();
|
||||
System.out.println("done");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user