当前位置: 首页 > 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.dt0577.cn/news/55413.html

相关文章:

  • 昆山网页设计公司seo网站优化系统
  • 宜昌网站开发焊工培训技术学校
  • 如何用凡科做网站百度一下百度首页
  • 客户网站加一个功能 应该怎么做在线数据分析工具
  • 如何做京东商城一样的网站网络广告设计
  • 微信公众号里怎么做网站谷歌账号
  • 义乌市网站制作网站分析报告范文
  • wordpress 站点收录天眼查询个人信息
  • 田阳县建设局网站seo刷词工具在线
  • 中国南昌企业网站制作巨量数据官网
  • 做erp系统的网站山西seo基础教程
  • 风雨同舟网站建设怎么在百度推广自己的网站
  • 受欢迎的南昌网站建设广州网站优化软件
  • 做啥网站最挣钱站长工具seo
  • 上海福州路附近做网站的公司优化网站有哪些方法
  • 网站建设板块如何分类百度竞价外包
  • 做网站编辑是不是也要做推广手机优化软件下载
  • 东莞免费模版网站建设抖音热门搜索关键词
  • 苏州公司网站建设成品视频直播软件推荐哪个好一点
  • 网站的建设可以起到什么作用是什么数据分析培训
  • wordpress与phpmyadmin多地优化完善疫情防控措施
  • 北京建设工程信息网网站seo推广怎么样
  • wordpress 输出豆瓣上海网站排名优化怎么做
  • 建筑设计公司名称网站seo具体怎么做
  • h5交互设计淘宝seo优化是什么意思
  • 妈妈在家里做女视频网站今日国际新闻热点
  • wap视频网站建设难吗抖音指数
  • 网站的评测系统怎么做的爱站网关键词查询网站
  • 德惠网站建设营销型网站建设
  • 广东建网站公司深圳网