当前位置: 首页 > news >正文

做电容的网站网站建设攵金手指专业

做电容的网站,网站建设攵金手指专业,哈尔滨网站建设公司有哪些,母婴行业网站建设并发库中的BlockingQueue是一个比较好玩的类#xff0c;顾名思义#xff0c;就是阻塞队列。该类主要提供了两个方法put()和take()#xff0c;前者将一个对象放到队列中#xff0c;如果队列已经满了#xff0c;就等待直到有空闲节点#xff1b;后者从head取一个对象#… 并发库中的BlockingQueue是一个比较好玩的类顾名思义就是阻塞队列。该类主要提供了两个方法put()和take()前者将一个对象放到队列中如果队列已经满了就等待直到有空闲节点后者从head取一个对象如果没有对象就等待直到有可取的对象。 下面的例子比较简单一个读线程用于将要处理的文件对象添加到阻塞队列中 另外四个写线程用于取出文件对象为了模拟写操作耗时长的特点特让线程睡眠一段随机长度的时间。另外该Demo也使用到了线程池和原子整型 AtomicIntegerAtomicInteger可以在并发情况下达到原子化更新避免使用了synchronized而且性能非常高。由 于阻塞队列的put和take操作会阻塞为了使线程退出特在队列中添加了一个“标识”算法中也叫“哨兵”当发现这个哨兵后写线程就退出。 当然线程池也要显式退出了。 package concurrent;import java.io.File;import java.io.FileFilter;import java.util.concurrent.BlockingQueue;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.concurrent.LinkedBlockingQueue;import java.util.concurrent.atomic.AtomicInteger;public class TestBlockingQueue {  static long randomTime() {    return (long) (Math.random() * 1000);  }  public static void main(String[] args) {    // 能容纳100个文件    final BlockingQueueFile queue  new LinkedBlockingQueueFile(100);    // 线程池    final ExecutorService exec Executors.newFixedThreadPool(5);    final File root  new File(F:\\JavaLib);    // 完成标志    final File exitFile  new File();    // 读个数    final AtomicInteger rc  new AtomicInteger();    // 写个数    final AtomicInteger wc  new AtomicInteger();    // 读线程    Runnable read  new Runnable() {      public void run() {        scanFile(root);        scanFile(exitFile);      }      public void scanFile(File file) {        if (file.isDirectory()) {          File[] files file.listFiles(new FileFilter() {            public boolean accept(File pathname) {              return pathname.isDirectory()                  || pathname.getPath().endsWith(.java);            }          });          for (File one : files)            scanFile(one);        } else {          try {            int index rc.incrementAndGet();            System.out.println(Read0:   index                    file.getPath());            queue.put(file);          } catch (InterruptedException e) {          }        }      }    };    exec.submit(read);    // 四个写线程    for (int index  0; index  4; index) {      // write thread      final int NO index;      Runnable write  new Runnable() {        String threadName  Write  NO;        public void run() {          while (true) {            try {              Thread.sleep(randomTime());              int index wc.incrementAndGet();              File file queue.take();              // 队列已经无对象              if (file exitFile) {                // 再次添加标志以让其他线程正常退出                queue.put(exitFile);                break;              }              System.out.println(threadName  :   index                      file.getPath());            } catch (InterruptedException e) {            }          }        }      };      exec.submit(write);    }    exec.shutdown();  }} 转http://blog.sina.com.cn/s/blog_67b077fe0100zrv9.html 转载于:https://www.cnblogs.com/sunxucool/archive/2013/03/13/2957377.html
http://www.yutouwan.com/news/186534/

相关文章:

  • 珠海营销营网站建设公司js做网站预览效果
  • 黄页网站大全通俗易懂wordpress主题lenews
  • 做外贸要有英文网站吗做网站目录
  • 浅蓝色.net企业网站源码带后台北京网站制作很好 乐云践新
  • 做网站一定要有服务器吗wordpress企业主题模板下载
  • 怎么做seo网站推广营销软件代理品牌有哪些
  • 通化网站建设单位成都学网站建设
  • 哪个网站做淘宝客最合适家装公司名称
  • 霸州建网站wordpress制作友情链接
  • 网站开发 费用安徽最新消息
  • 建站的费用前端素材网站
  • wordpress 站点换域名南京微信网站建设哪家好
  • 网站的橱窗怎么做wordpress 注册没密码
  • 外贸 网站 源码注册深圳公司
  • 公司网站如何做分录权威做网站的公司
  • 杭州网站建设公司电话个人网站的设计流程
  • 程序员自己建站赚钱南部县房产网
  • 品牌型网站设计做门户网站用什么软件
  • 网站开发工程师学什么区别潍坊住房和城乡建设厅网站电话
  • 需要锦州网站建设c# 网站开发实例教程
  • 怎么买域名建网站给网站做选题
  • 重庆触摸屏_电子商务网站建设网上找工程平台有哪些
  • 网站打开出现建设中定制网站与模板网站
  • 盗版系统网站怎么建立三星网上商城下载
  • 学习网站 现状wordpress错误代码403
  • 顺德企业网站制作百度竞价排名事件
  • 做报纸版式的网站江苏网站seo平台
  • 国内html网站欣赏有谁想做网站 优帮云
  • 5118网站查询做一份网站的步zou
  • 网站健设推广产品多少钱营销型网站的评价