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

电视网站免费大全做影视网站挣钱吗

电视网站免费大全,做影视网站挣钱吗,奥派网站建设,金华网站建设团队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.15wanjia.com/news/188758.html

相关文章:

  • 创建网站的三种方法wordpress不支持中文
  • 帮做网站制作挣钱怎样查网站和增加网站
  • 麻栗坡做网站业务平台
  • 网页制作与网站制作网站模板和后台
  • 网站推广引流织梦dedecms医院类网站在线预约挂号插件_utf8
  • 网站开发过程说明怎么写住房和城乡建设部令第37号
  • 高水平高职院校 建设网站利用access数据库做网站
  • 建筑图纸网站化妆品网站设计论文
  • 微信小程序制作团队广州网站制作实力乐云seo
  • 苏州网站建设创意修改图片网站
  • 微网站开发不用模板什么网站是做家教的
  • 西宁网站建设加q479185700深圳龙华汽车网站建设
  • 网站开发人员应该用什么浏览器如何保存个人网站
  • 吉安县规划建设局网站微信公众号对接wordpress教程
  • wordpress php环境搭建广州企业网站seo
  • 网站建设一般多少钱沈阳点金网站建设
  • 注册网站公司淘宝详情页psd模板免费
  • 武进网站建设wordpress二维码制作
  • 视听节目 网站建设长沙功能网站建设
  • 做毕业设计实物的网站深圳网站优化最好的方法
  • 深圳的设计网站大全上海的室内设计公司
  • 物流网站建设与管理建设网站空间多少钱
  • 网站改版需要怎么做服装设计网站素材
  • 青岛网站建设好不好WordPress首页怎么打开
  • 整站wordpress下载wordpress如何适配手机端
  • 国外好的设计网站有哪些财务网站模板
  • wordpress网站鼠标衡阳网站建设公司
  • 个人做网站流程图新乡微信网站建设
  • 免费做网站模板在哪里做自动化培训机构排名
  • 河北黄骅市网站建设天华建筑设计公司官网