private static final Unsafe THE_UNSAFE;
static{
try {
final PrivilegedExceptionAction<Unsafe> action = new PrivilegedExceptionAction<Unsafe>() {
public Unsafe run() throws Exception {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
return (Unsafe) theUnsafe.get(null);
}
};
THE_UNSAFE = AccessController.doPrivileged(action);
}
catch (Exception e){
throw new RuntimeException("Unable to load unsafe", e);
}
}
Java8获取Unsafe实例的正确方式
最新推荐文章于 2024-10-05 16:05:57 发布