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

做python一个网站做一个网站能卖多少钱

做python一个网站,做一个网站能卖多少钱,怎样做网站卖自己的产品教程,微网站模板标签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/188381.html

相关文章:

  • 免费企业网站模板源码教育类小程序开发
  • 以前做视频的网站旅游网站建设报价方案
  • 简洁软件下载网站源码一级造价工程师准考证打印时间
  • 哪个网站可以用MC皮肤做图片wordpress 流媒体
  • 婚庆公司网站模板网站建设 响应式 北京
  • 注册一个网站流程怎么样建立网站方案
  • 天津专业网站策划公司wordpress nova
  • 柳市做网站微信官网下载2020最新版
  • 电子商务网站需要做那些准备工作校园网站设计方案
  • 做一个京东网站怎么做的人性本私 wordpress
  • 哪里网站建设联系蓝色风格企业网站
  • 做网站怎么加弹幕青岛网站建设公司怎么样
  • 下载官方网站app大型门户网站建设方案
  • 织梦做的网站不能用手机访问重庆装修贷款利率是多少
  • 网站页面设计内容手把手教你做网站
  • 北海哪里做网站wordpress 图片采集器
  • 什么网站做海报网站建设模板是什么意思
  • 响应式网站是什么做网站工资高吗
  • 网站禁止访问软件开发专业名词
  • 温州企业建站程序wordpress做商城网站吗
  • 学习制作网页的网站专业微网站建设公司首选
  • 清远 网站建设婚恋网站建设公司排名
  • 黄江镇做网站黄石网站设计公司
  • 福州网站营销域名 做网站和邮箱
  • 电商网站建设重要性网站如何添加百度商桥
  • 做网站需要跟客户了解什么郴州seo服务
  • 网站栏目合理性成都美誉网站设计
  • 网站建设设计方案书常州做企业网站
  • 网站备案号查询系统线上营销是什么意思
  • 鹤壁做网站公司电话app开发费用计入什么科目