public class unSafeArrayDemo {

    private static final sun.misc.Unsafe UNSAFE;
private static final long TBASE;
private static final int TSHIFT; static {
int ts;
try {
UNSAFE = getUnsafe();
TBASE = UNSAFE.arrayBaseOffset(String[].class);
ts = UNSAFE.arrayIndexScale(String[].class);
} catch (Exception e) {
throw new Error(e);
}
TSHIFT = 31 - Integer.numberOfLeadingZeros(ts);
} static Unsafe getUnsafe() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
Unsafe unsafe = (Unsafe)f.get(null);
return unsafe;
} @SuppressWarnings("unchecked")
static final String entryAt(String[] tab, int i) {
return (String) UNSAFE.getObjectVolatile(tab, ((long)i << TSHIFT) + TBASE);
} public static void main(String[] args) {
int nLen = 37;
String[] table = new String[nLen];
for (int i = 0; i < nLen; i++) {
table[i] = "数值为: " + String.valueOf(i + 26);
}
String str = entryAt(table, 23);
System.out.println(str);
} }

  

最新文章

  1. #研发解决方案#分布式并行计算调度和管理系统Summoner
  2. C++调用shell
  3. 网站实现特定某个地区访问执行跳转(js方法)
  4. Android性能优化(一)
  5. JS insertAdajcentHTML 方法简介
  6. centos6.4yum搭建lamp环境
  7. 中文编码、字符集,GBK, UTF-8的概念
  8. TP中不区分大小写__APP__和__URL__的注意事项
  9. C++ 读写文件流
  10. paper 7:支持向量机系列四:Outliers —— 介绍支持向量机使用松弛变量处理 outliers 方法。
  11. socket 发送发送HTTP请求
  12. Codeforces 15B Laser
  13. HDU 1853Cyclic Tour(网络流之最小费用流)
  14. 织梦dedecms返回上一级链接代码
  15. ThinkPHP使用方法
  16. c/c++浮点数在内存中存储方式
  17. 模块的语法 import ,from...import....
  18. 1053. Path of Equal Weight (30)
  19. CrackME 2011 # 2 逆向练习解题思路
  20. ASP.NET MVC 常用路由总结

热门文章

  1. 『cs231n』线性分类器损失函数
  2. python-day32--进程---&gt;socker并发
  3. python-day8-字典的内置方法
  4. 二叉树—-1(No.9HN省赛小题)
  5. 部署docker-registry私有仓库
  6. 获取Oracle数据库awr报告方法
  7. 国际音标en
  8. git HEAD游离状态问题解决
  9. java web中的多条件查询
  10. Linux C:access()时间条件竞争漏洞