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

me域名网站wordpress框架视频

me域名网站,wordpress框架视频,石家庄手机网站建设公司,如何自己免费做网站Worker-Thread模式类似于工厂流水线#xff0c;有时也称为流水线设计模式。线程池在某种意义上也算是Worker-Thread模式的一种实现#xff0c;线程池初始化时创建线程类似于在流水线等待工作的工人#xff0c;提交给线程池的Runnable接口类似于需要加工的产品#xff0c;Ru…    Worker-Thread模式类似于工厂流水线有时也称为流水线设计模式。线程池在某种意义上也算是Worker-Thread模式的一种实现线程池初始化时创建线程类似于在流水线等待工作的工人提交给线程池的Runnable接口类似于需要加工的产品Runnable的run方法相当于组装该产品的说明书。Worker-Thread模式需要如下几个角色 流水线工人对传送带上的产品进行加工 流水线传送带用于传送来自上游的产品 产品组装说明书用于说明该产品如何组装 Worker-Thread模式中生产线保存了在处理中的产品并且是启动生产线的线程后生产线启动若干数量的流水线工人线程 生产线聚合了产品和工人。生产者消费者模式是单纯的依赖关系生产者和消费者都依赖产品队列生产者和消费者是相互不知道。   示例代码如下 public abstract class InstructionBook { protected abstract void firstProcess(); protected abstract void secondProcess();public final void create() { this.firstProcess(); this.secondProcess(); }} public class Production extends InstructionBook{ private final int productId;public Production(int productionId) { this.productIdproductionId; }public int getProductionId() { return this.productId; }Override protected void firstProcess() { System.out.println(execute the this.productId first process); }Override protected void secondProcess() { System.out.println(execute the this.productId second process); }} import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit;public class Worker extends Thread{ private final ProductionChannel channel;public Worker(String workerName, ProductionChannel channel) { super(workerName); this.channelchannel; }public void run() { while(true) { try { Production productionthis.channel.takeProduction(); System.out.println(getName() process the production.getProductionId()); production.create(); TimeUnit.SECONDS.sleep(ThreadLocalRandom.current().nextInt(5)); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }} import java.util.ArrayList;public class ProductionChannel { private final ArrayListProduction productionQueuenew ArrayList(); private int total20; private final Worker[] workers;public ProductionChannel(int workerSize) { this.workersnew Worker[workerSize]; for(int i0;iworkerSize;i) { workers[i]new Worker(Worker-i,this); workers[i].start(); } }public void offerProduction(Production production) { synchronized(this) { while(totalthis.productionQueue.size()) { try { System.out.println(processing production idproduction.getProductionId() , in waiting state); this.wait(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println(processing production idproduction.getProductionId()); this.productionQueue.add(production); this.notifyAll(); } }public Production takeProduction() { synchronized(this) { while(this.productionQueue.size()0) { try { System.out.println(processing to fetch production, while in waiting state); this.wait(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } this.notifyAll(); Production pthis.productionQueue.get(0); this.productionQueue.remove(0); return p; } }} import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream;public class WTtest {public static void main(String[] args) { ProductionChannel channelnew ProductionChannel(5); AtomicInteger pidnew AtomicInteger(); IntStream.range(1, 8).forEach(i-new Thread(()-{ // while(true) { channel.offerProduction(new Production(pid.getAndIncrement())); try { TimeUnit.SECONDS.sleep(ThreadLocalRandom.current().nextInt(5)); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // } }).start()); }}
http://www.w-s-a.com/news/86987/

相关文章:

  • 深圳市专注网站建设全网营销网络推广
  • 如何快速建设网站虚拟空间软件
  • 一个虚拟主机可以做几个网站免费软件下载中心
  • 美工培训网站中国建筑网官网手机版
  • 创建网站花钱吗谁能给个网址免费的
  • 宁波教育学会网站建设网站建设价格由什么决定
  • 北京定制网站价格wordpress上传pdf文档
  • 网站建设费税率dz论坛seo设置
  • 推销网站话术商业网站开发与设计
  • 金华网站建设哪个网站做欧洲旅行比较好
  • 东莞市住房和城乡建设局网站trswcm网站建设
  • 郑州做网站企业h5编辑器免费版
  • 加强公司窗口网站建设陕西省外省入陕建筑信息平台
  • 成都网站优化实战大连企业网站建设模板
  • 服务器硬件影响网站速度seo网站推广价格
  • 学院网站开发竞争对手分析买网站送域名
  • 手机网站 jsp个人网页制作成品代码五个页面
  • ppt做长图网站wordpress文章页面图片自动适应
  • 做泌尿科网站价格京东商城网站建设教程
  • 像网站的ppt怎么做的移动app与网站建设的区别
  • 怎么建个人网站网站收录有什么用
  • 广州市医院网站建设广州头条新闻最近一周
  • 广州移动 网站设计中国交通建设监理协网站
  • 甘肃省第八建设集团公司网站wordpress topnews
  • 公司网站建设维保协议wordpress会员可看
  • 合肥百度网站排名优化深圳集团网站开发公司
  • 可以直接打开网站的方法手机回收站
  • 山西免费网站制作中天建设集团有限公司第九建设公司
  • 好的网站有哪些企业微信开发者工具
  • 网站通栏代码老外做的中国汉字网站