摘要: Java中有一个BlockingQueue可以用来充当堵塞队列,下面是一个桌面搜索的设计package net.jcip.examples;import java.io.File;import java.io.FileFilter;import java.util.concurrent.*;/** * ProducerConsumer * * Producer and consumer tasks in a desktop search application * */public class ProducerConsumer { static class FileCrawler im... 阅读全文
posted @ 2013-09-05 21:03 张兰云 阅读(436) 评论(0) 推荐(0) 编辑
摘要: 1.原子变量(java.util.concurrent.atomic) 原子状态,变化不会被打断,如 AtomicLong , AtomicInteger2.内部锁 synchronized 块 synchronized方法的锁就是方法所在的对象本身,可重入3.共享变量 Volatile变量,每次从内存取出数据,可以获得最新的副本。 没有同步情况下的共享变量,可能执行顺序不是按照代码的组织, public class NoVisibility{ private static boolean ready; private static int number; ... 阅读全文
posted @ 2013-09-05 18:02 张兰云 阅读(409) 评论(0) 推荐(0) 编辑