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

爱站网是什么平台关键词搜索排名怎么查看

爱站网是什么平台,关键词搜索排名怎么查看,3d效果图教程网站,简单的响应式网页实例Worker-Thread模式类似于工厂流水线,有时也称为流水线设计模式。线程池在某种意义上也算是Worker-Thread模式的一种实现,线程池初始化时创建线程类似于在流水线等待工作的工人,提交给线程池的Runnable接口类似于需要加工的产品,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.productId=productionId;
}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.channel=channel;
}public void run() {
while(true) {
try {
Production production=this.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 ArrayList<Production> productionQueue=new ArrayList<>();
private int total=20;
private final Worker[] workers;public ProductionChannel(int workerSize) {
this.workers=new Worker[workerSize];
for(int i=0;i<workerSize;i++) {
workers[i]=new Worker("Worker-"+i,this);
workers[i].start();
}
}public void offerProduction(Production production) {
synchronized(this) {
while(total<=this.productionQueue.size()) {
try {
System.out.println("processing production id="+production.getProductionId()+" , in waiting state");
this.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("processing production id="+production.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 p=this.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 channel=new ProductionChannel(5);
AtomicInteger pid=new 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.ds6.com.cn/news/40419.html

相关文章:

  • 高端网站设计公司如何设计网站杭州云优化信息技术有限公司
  • 杭州如何设计网站首页学生个人网页制作html代码
  • 中企动力网站后台品牌推广方案策划书
  • 网站托管费用多少免费推广公司的网站
  • 怎样建设有价值的网站厦门网站推广优化哪家好
  • 百度地图实时街景怎么移动百度seo优化培训
  • 江苏建设省直报名网站培训班学员培训心得
  • 学做网站推广要多久时间万能优化大师下载
  • cms可以做多少个网站网络推广方法有几种
  • 用websocket做网站网站子域名查询
  • 成都网站建设需多少钱温州seo优化公司
  • 云一网站建设群站优化之链轮模式
  • 网站更新问题在线seo工具
  • b2c的电子商务网站有哪些近日发生的重大新闻
  • 绍兴市住房与城乡建设厅网站搜狐财经峰会
  • 锦州做网站的公司十大洗脑广告
  • 成都网站设计得多少钱杭州seo首页优化软件
  • 自己做的网站怎么发布win7网络营销策略都有哪些
  • 内网网站开发费用爱上链外链购买交易
  • 阿里云网站实名认证友情链接交换系统
  • 网站域名注册证书搜索引擎优化seo网站
  • 求哪位大神发人和动物做愛视频网站网站权重是什么意思
  • 网站开发课题研究背景营销软件哪个好
  • 百度公众号河南整站百度快照优化
  • 如何接单做网站关键词排名优化公司成都
  • 中英文微信网站建设网络推广文案怎么写
  • 云南省城乡建设厅网站站长之家网站
  • 最新的即时比分百度关键词优化专家
  • 网站备案需要年检吗免费微信引流推广的方法
  • 专业网站建设机构网站如何在百度刷排名