1.通过Unsafe类可以分配内存,可以释放内存:类中提供的3个本地方法allocateMemory.reallocateMemory.freeMemory分别用于分配内存,扩充内存和释放内存,与C语言中的3个方法对应.2.可以定位对象某字段的内存位置,也可以修改对象的字段值,即使它是私有的:[java] view plaincopyprint?public native long allocateMemory(long l); public native long reallocateMemo…
一.指令重排序 例子如下: public class Visibility1 { public static boolean ready; public static int number; } public class ReaderThread extends Thread { @Override public void run() { while (!Visibility1.ready){ Thread.yield(); System.out.println(Visibility1.numb…
1.ThreadPoolExecutor类 java.uitl.concurrent.ThreadPoolExecutor类是线程池中最核心的一个类,下面我们来看一下ThreadPoolExecutor类的具体实现源码(内容基于JDK1.7). 在ThreadPoolExecutor类中提供了四个构造方法: public class ThreadPoolExecutor extends AbstractExecutorService { ..... public ThreadPoolExe…