Thread t1 = new Thread(new Product(new Resource()));其实是堆与堆的通信,堆是一个运行时数据区,要在运行时动态分配内存,存取速度较慢。
Resource r = new Resource();
Product p = new Product(r);
Cutmor c = new Cutmor(r);
Thread t1 = new Thread(p);
Thread t2 = new Thread(c);
是栈与堆的通信,栈的优势是,存取速度比堆要快,仅次于寄存器,栈数据可以共享。 |
|