一般情况下,常见获取Unsafe实体的代码是这样写的:
try
{
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
THE_UNSAFE = (Unsafe)theUnsafe.get(null);
}
catch (Exception e)
{
throw new RuntimeException("Unable to load unsafe", e);
}
这里再插一个网上资料,http://files.cnblogs.com/jobs/Java并发程序设计教程-2010-08-10.pdf
非常不错的并发编程总结,这里鼎力推荐一下。