摘要: 1.使用线程同步机制,达到先支出后收入的效果。 1 public class AccountTest{ 2 3 public static void main(String[] args){ 4 final Account acc = new Account... 阅读全文
posted @ 2015-06-12 18:01 a ray of sunshine 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 1. synchronized的作用synchronized类似于win32中的临界区,临界区的作用:对于共享的全局变量,在多个线程并发的情况下,对这样的全局变量的读写就会发生读写的冲突,使得全局变量的读写,能够以原子的方式被执行,而不是一个线程要读取全局数据时候,由于线程调度,而另一个线程则此时被... 阅读全文
posted @ 2015-06-12 15:16 a ray of sunshine 阅读(2395) 评论(0) 推荐(0) 编辑
摘要: 1.启动两个线程 1 public class ThreadTest { 2 3 public static boolean isRun = false; 4 5 @Test 6 public void mainTest(){ 7 System.o... 阅读全文
posted @ 2015-06-12 11:38 a ray of sunshine 阅读(212) 评论(0) 推荐(0) 编辑