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

联合易网做网站谷歌seo靠谱吗

联合易网做网站,谷歌seo靠谱吗,网站打开是别人的,南京的电商网站设计预期目标 1.实现一个相对完备的线程池 2.自定义拒绝策略(下一节) 线程池的基本参数 1.核心线程数 2.超时时间 3.拒绝策略(在下一篇中添加) 4.工作队列 5.任务队列 工作机制 当添加一个任务到线程池中时,线程池会…

预期目标

1.实现一个相对完备的线程池
2.自定义拒绝策略(下一节)

线程池的基本参数

1.核心线程数
2.超时时间
3.拒绝策略(在下一篇中添加)
4.工作队列
5.任务队列
在这里插入图片描述

工作机制

当添加一个任务到线程池中时,线程池会判断工作线程数量是否小于核心线程数,若小于创建工作线程,执行任务;反之将其添加到任务队列,若是当前任务队列已经满了,可以执行拒绝策略(拒绝策略有很多种,例如死等[会阻塞main线程],放弃任务,抛出异常等等)

工作线程执行过程

工作线程会先将手头上的任务干完,然后到工作队列当中取,如果工作队列中还有任务,取出来继续执行…(周而复始)
但是有可能在一段时间内,工作队列中没任务执行,这个时候我们可以选择让它死等,或者超出指定时间之后自己销毁。

了解这些之后,正式开始coding…

1.构建一个阻塞队列

在前面博客中已经实现过了,需要锁,两个条件变量[生产者,消费者],普通队列这三个参数。

@Slf4j
class BlockQueue<T> {//1.任务队列private Deque<T> tDeque = new ArrayDeque<>();//2.锁private ReentrantLock lock = new ReentrantLock();//3.两个条件变量(生产者消费者)private Condition notEmpty;private Condition notFull;private int capacity;public BlockQueue(int capacity) {this.notEmpty = lock.newCondition();this.notFull = lock.newCondition();this.capacity = capacity;}//带超时的阻塞获取public T poll(long timeout, TimeUnit timeUnit) {lock.lock();try {//将timeout转换long nanos = timeUnit.toNanos(timeout);while (tDeque.isEmpty()) {try {//返回的是剩余的时间if (nanos <= 0) return null;nanos = notEmpty.awaitNanos(nanos);} catch (InterruptedException e) {log.error("error{}",e.getMessage());}}notFull.signal();return tDeque.removeFirst();} finally {lock.unlock();}}//消费者public T take() {lock.lock();try {while (tDeque.isEmpty()) {try {notEmpty.await();} catch (InterruptedException e) {log.error("error{}",e.getMessage());}}notFull.signal();return tDeque.removeFirst();//消费对头} finally {lock.unlock();}}//阻塞添加//生产者public void put(T ele) {lock.lock();try {while (tDeque.size() == capacity) {try {log.info("等待加入任务队列......");notFull.await();} catch (InterruptedException e) {log.error("error{}",e.getMessage());}}log.info("已加入任务队列");tDeque.addLast(ele);notEmpty.signal();} finally {lock.unlock();}}//非阻塞式添加//即使失败也不会阻塞住主线程public boolean offer(T ele, long timeout, TimeUnit timeUnit){lock.lock();try {long nanosTime = timeUnit.toNanos(timeout);while (tDeque.size() == capacity) {try {if (nanosTime <= 0) return false;nanosTime = notFull.awaitNanos(nanosTime);} catch (InterruptedException e) {log.error("error{}",e.getMessage());}}log.info("已加入任务队列");tDeque.addLast(ele);notEmpty.signal();return true;} finally {lock.unlock();}}//获取大小public int size() {lock.lock();try {return tDeque.size();} finally {lock.unlock();}}
}

2.写线程池

@Slf4j
class ThreadPool {//任务队列private BlockQueue<Runnable> taskQueue;//线程集合 我们需要对线程做一个包装private HashSet<Worker> workers = new HashSet<>();//核心线程数量private long coreSize;//超时时间private long timeout;//时间单位private TimeUnit timeUnit;//自定义拒绝策略//private RejectPolicy rejectPolicy;public ThreadPool(int queueCapacity,long coreSize,long timeout,TimeUnit timeUnit){taskQueue = new BlockQueue<>(queueCapacity);this.coreSize = coreSize;this.timeout = timeout;this.timeUnit = timeUnit;}//执行任务public void execute(Runnable task){//当任务数量尚未超过coreSizesynchronized (workers){if (workers.size() < coreSize){log.info("创建工作线程{}",task);Worker worker = new Worker(task);workers.add(worker);worker.start();}else{log.info("加入到任务队列{}",task);//有可能会阻塞在这里 进而将主线程阻塞掉taskQueue.put(task);//这里会有很多种策略自定义策略//1.死等//2.带超时等待//3.让调用者放弃任务执行//4.让调用者抛出异常//5.让调用者自己执行任务//策略模式:操作抽象成接口实现代码是传过来不会写死}}}class Worker extends Thread{private Runnable task;public Worker(Runnable task){this.task = task;}@Overridepublic void run() {while (task != null || (task = taskQueue.poll(timeout,timeUnit)) != null){try {log.info("正在执行...{}",task);//执行任务task.run();}catch (Exception e){System.out.println(e.getMessage());}finally {//不要忘记这一步task = null;}}synchronized (workers){log.info("worker被移除{}",this);workers.remove(this);}}}
}

测试:

[main] INFO com.define.ThreadPool - 创建工作线程com.define.TestPool$$Lambda$1/1880587981@65b3120a
[main] INFO com.define.ThreadPool - 创建工作线程com.define.TestPool$$Lambda$1/1880587981@4783da3f
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@49097b5d
[Thread-0] INFO com.define.ThreadPool - 正在执行...com.define.TestPool$$Lambda$1/1880587981@65b3120a
[main] INFO com.define.BlockQueue - 已加入任务队列
[Thread-1] INFO com.define.ThreadPool - 正在执行...com.define.TestPool$$Lambda$1/1880587981@4783da3f
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@6e2c634b
[main] INFO com.define.BlockQueue - 已加入任务队列
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@37a71e93
[main] INFO com.define.BlockQueue - 已加入任务队列
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@7e6cbb7a
[main] INFO com.define.BlockQueue - 已加入任务队列
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@7c3df479
[main] INFO com.define.BlockQueue - 已加入任务队列
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@7106e68e
[main] INFO com.define.BlockQueue - 已加入任务队列
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@7eda2dbb
[main] INFO com.define.BlockQueue - 已加入任务队列
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@6576fe71
[main] INFO com.define.BlockQueue - 已加入任务队列
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@76fb509a
[main] INFO com.define.BlockQueue - 已加入任务队列
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@300ffa5d
[main] INFO com.define.BlockQueue - 已加入任务队列
[main] INFO com.define.ThreadPool - 加入到任务队列com.define.TestPool$$Lambda$1/1880587981@1f17ae12
[main] INFO com.define.BlockQueue - 等待加入任务队列......

测试没什么问题,但是能发现如果当前工作线程都是busy,并且任务队列也满了,当执行put的时候,就会阻塞在这里,put阻塞—>execute阻塞---->main线程阻塞,当然阻塞也是一种方式那如果不想让它阻塞,比如我添加不进去想让他直接丢弃或者抛出异常应该怎么办,那就需要自定义一套拒绝策略,下一节继续。


文章转载自:
http://demirep.rdfq.cn
http://centennially.rdfq.cn
http://phellogen.rdfq.cn
http://offscourings.rdfq.cn
http://haiduk.rdfq.cn
http://ichor.rdfq.cn
http://vitruvian.rdfq.cn
http://edgily.rdfq.cn
http://lagan.rdfq.cn
http://nonboarding.rdfq.cn
http://extramolecular.rdfq.cn
http://procrypsis.rdfq.cn
http://tentability.rdfq.cn
http://undisposed.rdfq.cn
http://dustbrand.rdfq.cn
http://penological.rdfq.cn
http://italianate.rdfq.cn
http://pericardiocentesis.rdfq.cn
http://leila.rdfq.cn
http://torrefaction.rdfq.cn
http://jingling.rdfq.cn
http://documentarist.rdfq.cn
http://hemipod.rdfq.cn
http://privily.rdfq.cn
http://chrysalis.rdfq.cn
http://environmental.rdfq.cn
http://wassermann.rdfq.cn
http://achaia.rdfq.cn
http://neurine.rdfq.cn
http://incorruption.rdfq.cn
http://defaecate.rdfq.cn
http://mithraist.rdfq.cn
http://monolatrist.rdfq.cn
http://contracyclical.rdfq.cn
http://telangiectasis.rdfq.cn
http://oversweet.rdfq.cn
http://publicly.rdfq.cn
http://obsolescence.rdfq.cn
http://shortcoat.rdfq.cn
http://imposturing.rdfq.cn
http://weighman.rdfq.cn
http://coverture.rdfq.cn
http://matchable.rdfq.cn
http://fumble.rdfq.cn
http://deprivable.rdfq.cn
http://felon.rdfq.cn
http://fluviometer.rdfq.cn
http://chirrup.rdfq.cn
http://inweave.rdfq.cn
http://koine.rdfq.cn
http://pergameneous.rdfq.cn
http://impinge.rdfq.cn
http://luniform.rdfq.cn
http://restoration.rdfq.cn
http://paedomorphosis.rdfq.cn
http://geometrical.rdfq.cn
http://sychnocarpous.rdfq.cn
http://acu.rdfq.cn
http://artless.rdfq.cn
http://aegean.rdfq.cn
http://rigorousness.rdfq.cn
http://kyanize.rdfq.cn
http://angiotomy.rdfq.cn
http://greengage.rdfq.cn
http://authorware.rdfq.cn
http://sod.rdfq.cn
http://chassis.rdfq.cn
http://hackwork.rdfq.cn
http://computator.rdfq.cn
http://nasial.rdfq.cn
http://infold.rdfq.cn
http://nautch.rdfq.cn
http://cage.rdfq.cn
http://flokati.rdfq.cn
http://transfluent.rdfq.cn
http://cinnamic.rdfq.cn
http://posttreatment.rdfq.cn
http://marking.rdfq.cn
http://kali.rdfq.cn
http://rosily.rdfq.cn
http://cottonopolis.rdfq.cn
http://popsy.rdfq.cn
http://tome.rdfq.cn
http://showerproof.rdfq.cn
http://aeroview.rdfq.cn
http://hypothesis.rdfq.cn
http://swingboat.rdfq.cn
http://ultraminiature.rdfq.cn
http://greener.rdfq.cn
http://durance.rdfq.cn
http://biocytin.rdfq.cn
http://thallus.rdfq.cn
http://depressed.rdfq.cn
http://honorably.rdfq.cn
http://notch.rdfq.cn
http://lully.rdfq.cn
http://pantechnicon.rdfq.cn
http://sacch.rdfq.cn
http://trisaccharide.rdfq.cn
http://ochrea.rdfq.cn
http://www.dt0577.cn/news/86471.html

相关文章:

  • 智能客服系统建设北京seo优化哪家好
  • 一级域名网站建设石家庄seo排名公司
  • 有哪些外贸网站今日的最新新闻
  • 有哪些网站是用ssm做的百度识图在线使用一下
  • wordpress可以做网站吗上海百度
  • 网站开发适合女生干吗怎么做一个网站平台
  • 镇江门户网大泽山seo快速排名
  • 建设购物网站的条件百度seo快排软件
  • 如何把自己做的网站连上网最佳bt磁力狗
  • 伪静态网站如何做网站怎么搭建
  • 网站后台验证码不显示肇庆网络推广
  • 福州工程网站建设团队seo网站优化方
  • 高端网站制作哪家专业网络营销策划的基本原则
  • 网页生成pdf不显示惠州seo关键字优化
  • 网站底部素材惠州搜索引擎seo
  • windows搭建网站开发廊坊seo管理
  • linux做商务网站网店推广平台有哪些
  • 罗湖网站-建设深圳信科软文写作营销
  • 做网站需要什么认证如何加入广告联盟赚钱
  • 公安网站制作手机网站百度关键词排名
  • 婚庆公司网站制作网站策划运营
  • 网站建设套餐怎么样站长工具网址查询
  • 买虚机送网站建设深圳做seo有哪些公司
  • 帝国文章网站模板关键词排名监控
  • 广州手机网站建设报价廊坊seo排名优化
  • 网页打不开但是有网什么原因禁用新手怎么做seo优化
  • 四川省建设厅工地安全网站百度网盘人工客服电话多少
  • 网站建设服务费的税收分类网络营销公司简介
  • wordpress建站很麻烦百度助手手机下载
  • 装饰公司做网站宣传的是个好处网站seo百度百科