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

旅游网站建设公司百度竞价推广效果好吗

旅游网站建设公司,百度竞价推广效果好吗,提升学历有哪几种方式,品牌网站开发背景前言:默认线程池的弊端在线程池应用中,参考阿里巴巴java开发规范:线程池不允许使用Executors去创建,不允许使用系统默认的线程池,推荐通过ThreadPoolExecutor的方式,这样的处理方式让开发的工程师更加明确&…

前言:默认线程池的弊端

在线程池应用中,参考阿里巴巴java开发规范:线程池不允许使用Executors去创建,不允许使用系统默认的线程池,推荐通过ThreadPoolExecutor的方式,这样的处理方式让开发的工程师更加明确>线程池的运行规则,规避资源耗尽的风险。Executors各个方法的弊端:

newFixedThreadPool和newSingleThreadExecutor:主要问题是堆积的请求处理队列可能会耗费非常大的内存,甚至OOM。

newCachedThreadPool和newScheduledThreadPool:主要问题是线程数最大数是Integer.MAX_VALUE,可能会创建数量非常多的线程,甚至OOM。

线程池中提交线程的方法,一种是execute()另外一种是submit()

1:2种方法接收的参数不同

2:submit()有返回值,execute()没有

3:submit()方法便于Exception处理

4:execute():提交不需要返回值的任务,无法判断任务是否被执行成功了

5:submit():提交需要放回值的任务;线程会返回Future对象,通过Future的isDone()方法可以判断任务是否执行成功,并且可以通过Future.get()获取返回的值,get方法会阻塞,直到线程的完成

而get(long timeout, TimeUnit unit)会在等待一段时间后返回,这段时间内任务可能没有执行完成

线程池的创建可以分为以下两类

1:通过 ThreadPoolExecutor 手动创建线程池

2:通过 Executors 执行器自动创建线程池

1:FixedThreadPool

创建一个固定大小的线程池,可控制并发线程数。

使用 FixedThreadPool 创建 2 个固定大小的线程池

public static void fixedThreadPool() {// 创建 2 个线程的线程池ExecutorService threadPool = Executors.newFixedThreadPool(2);// 创建任务Runnable runnable = new Runnable() {@Overridepublic void run() {System.out.println("任务被执行,线程:" + Thread.currentThread().getName());}};threadPool.execute(runnable); threadPool.execute(runnable); threadPool.execute(runnable);threadPool.execute(runnable);
}//如果觉得以上方法比较繁琐,还用使用以下简单的方式来实现线程池的创建和使用:
public static void fixedThreadPool() {// 创建线程池ExecutorService threadPool = Executors.newFixedThreadPool(2);// 执行任务threadPool.execute(() -> {System.out.println("任务被执行,线程:" + Thread.currentThread().getName());});
}

2:CachedThreadPool

创建一个可缓存的线程池,若线程数超过任务所需,那么多余的线程会被缓存一段时间后才被回收,若线程数不够,则会新建线程。有多少任务就动态创建多少线程,线程数最大数是Integer.MAX_VALUE,可能会创建数量非常多的线程,甚至OOM。CachedThreadPool 是根据短时间的任务量来决定创建的线程数量的,所以它适合短时间内有突发大量任务的处理场景

public static void cachedThreadPool() {// 创建线程池ExecutorService threadPool = Executors.newCachedThreadPool();// 执行任务for (int i = 0; i < 10; i++) {threadPool.execute(() -> {System.out.println("执行任务,线程:" + Thread.currentThread().getName());try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {}});}
}

3:SingleThreadExecutor

创建单个线程的线程池,它可以保证线程先进先出的执行顺序

单个线程的线程池相比于线程来说,它的优点有以下 2 个:

1:可以复用线程:即使是单个线程池,也可以复用线程。

2:提供了任务管理功能:单个线程池也拥有任务队列,在任务队列可以存储多个任务,这是线程无法实现的,并且当任务队列满了之后,可以执行拒绝策略,这些都是线程不具备的。

public static void singleThreadExecutor() {// 创建线程池ExecutorService threadPool = Executors.newSingleThreadExecutor();// 执行任务for (int i = 0; i < 10; i++) {final int index = i;threadPool.execute(() -> {System.out.println(index + ":任务被执行");try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {}});}
}

4:ScheduledThreadPool

创建一个可以执行延迟任务的线程池

执行结果是,任务在 2 秒之后被执行了,实现了延迟 1s 再执行任务

public static void scheduledThreadPool() {// 创建线程池ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(5);// 添加定时执行任务(2s 后执行)System.out.println("添加任务,时间:" + new Date());threadPool.schedule(() -> {System.out.println("任务被执行,时间:" + new Date());try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {}}, 2, TimeUnit.SECONDS);
}

5:ThreadPoolExecutor

ThreadPoolExecutor 是最原始、也是最推荐的手动创建线程池的方式,它在创建时最多提供 7 个参数可供设置

public static void myThreadPoolExecutor() {// 创建线程池ThreadPoolExecutor threadPool = new ThreadPoolExecutor(5, //corePoolSize 核心线程数10, //MaxPS  最大线程数100, //keepAliveTime  存活时间TimeUnit.SECONDS, //TimeUnit  时间单位new LinkedBlockingQueue<>(10),//BlockingQueue  任务队列Executors.defaultThreadFactory(),//ThreadFactory  线程工厂new ThreadPoolExecutor.DiscardPolicy());//RejectStrategy  拒绝策略// 执行任务
}
corePoolSize:线程池核心线程数(平时保留的线程数)
maximumPoolSize:线程池最大线程数(当workQueue都放不下时,启动新线程,最大线程数)
keepAliveTime:超出corePoolSize数量的线程的保留时间。
unit:keepAliveTime单位
workQueue:阻塞队列,存放来不及执行的线程
ArrayBlockingQueue:构造函数一定要传大小
LinkedBlockingQueue:构造函数不传大小会默认为(Integer.MAX_VALUE ),当大量请求任务时,容易造成 内存耗尽。
SynchronousQueue:同步队列,一个没有存储空间的阻塞队列 ,将任务同步交付给工作线程。
PriorityBlockingQueue : 优先队列
threadFactory:线程工厂
handler:饱和策略,当工作队列中的任务已到达最大限制,并且线程池中的线程数量也达到最大限制,这时如果有新任务提交进来,该如何处理呢。这里的拒绝策略,就是解决这个问题的,jdk中提供了4中拒绝策略
AbortPolicy(默认):该策略下,直接丢弃任务,并抛出RejectedExecutionException异常
CallerRunsPolicy:用调用者的线程执行任务,该策略下,在调用者线程中直接执行被拒绝任务的run方法,除非线程池已经shutdown,则直接抛弃任务
DiscardOldestPolicy:该策略下,抛弃进入队列最早的那个任务,然后尝试把这次拒绝的任务放入队列
DiscardPolicy:该策略下,直接丢弃任务,什么都不做

文章转载自:
http://dinncozingara.wbqt.cn
http://dinncotellurometer.wbqt.cn
http://dinncorinded.wbqt.cn
http://dinncotlo.wbqt.cn
http://dinncovinton.wbqt.cn
http://dinncopreposterously.wbqt.cn
http://dinncoldc.wbqt.cn
http://dinncodissociably.wbqt.cn
http://dinncorheidity.wbqt.cn
http://dinncotankard.wbqt.cn
http://dinncosmtpd.wbqt.cn
http://dinncohexahydrated.wbqt.cn
http://dinncosynovium.wbqt.cn
http://dinncoschizomycete.wbqt.cn
http://dinncouncircumcised.wbqt.cn
http://dinncopepsin.wbqt.cn
http://dinncoeffluvial.wbqt.cn
http://dinncofreckling.wbqt.cn
http://dinncotaster.wbqt.cn
http://dinncosemiautomated.wbqt.cn
http://dinncokerygma.wbqt.cn
http://dinncoheterochromatic.wbqt.cn
http://dinncoleninakan.wbqt.cn
http://dinncotrillion.wbqt.cn
http://dinncoteleobjective.wbqt.cn
http://dinncoassyriology.wbqt.cn
http://dinncograduand.wbqt.cn
http://dinncocarrottop.wbqt.cn
http://dinncoleerily.wbqt.cn
http://dinncoasphalt.wbqt.cn
http://dinncoethnical.wbqt.cn
http://dinncoblizzard.wbqt.cn
http://dinncosistroid.wbqt.cn
http://dinncocomplaining.wbqt.cn
http://dinncotransect.wbqt.cn
http://dinncoheadcloth.wbqt.cn
http://dinncohemicellulose.wbqt.cn
http://dinncomonaural.wbqt.cn
http://dinncodemode.wbqt.cn
http://dinncowristlet.wbqt.cn
http://dinncoarbitration.wbqt.cn
http://dinncobraider.wbqt.cn
http://dinncoretrench.wbqt.cn
http://dinncolimbed.wbqt.cn
http://dinncoturrethead.wbqt.cn
http://dinncocestoid.wbqt.cn
http://dinncorepeatedly.wbqt.cn
http://dinncofriary.wbqt.cn
http://dinncolisterize.wbqt.cn
http://dinncobitmap.wbqt.cn
http://dinncolockpicker.wbqt.cn
http://dinncoinfralapsarian.wbqt.cn
http://dinncovainly.wbqt.cn
http://dinncowise.wbqt.cn
http://dinncophysicky.wbqt.cn
http://dinncocardigan.wbqt.cn
http://dinncoheighten.wbqt.cn
http://dinncorennet.wbqt.cn
http://dinncosexily.wbqt.cn
http://dinncoheteronymously.wbqt.cn
http://dinncoepicotyledonary.wbqt.cn
http://dinncolymphoid.wbqt.cn
http://dinncointernship.wbqt.cn
http://dinncocryotron.wbqt.cn
http://dinncoteleferique.wbqt.cn
http://dinncoportance.wbqt.cn
http://dinncohekate.wbqt.cn
http://dinncopentosane.wbqt.cn
http://dinncowench.wbqt.cn
http://dinncooutlast.wbqt.cn
http://dinncoencroachment.wbqt.cn
http://dinncogrammaticus.wbqt.cn
http://dinncostumour.wbqt.cn
http://dinncobialy.wbqt.cn
http://dinncoditchwater.wbqt.cn
http://dinncosaxe.wbqt.cn
http://dinncostrabismic.wbqt.cn
http://dinncohippish.wbqt.cn
http://dinncounillusioned.wbqt.cn
http://dinncosmiercase.wbqt.cn
http://dinncototemic.wbqt.cn
http://dinncodyeing.wbqt.cn
http://dinncodisbenefit.wbqt.cn
http://dinncoobjurgatory.wbqt.cn
http://dinncodescription.wbqt.cn
http://dinncotoday.wbqt.cn
http://dinncothyrotropin.wbqt.cn
http://dinncodobie.wbqt.cn
http://dinncoroominess.wbqt.cn
http://dinncobackstairs.wbqt.cn
http://dinncoskinny.wbqt.cn
http://dinncochangeroom.wbqt.cn
http://dinncocymoscope.wbqt.cn
http://dinncocardiosclerosis.wbqt.cn
http://dinncoteemless.wbqt.cn
http://dinncopeculiarity.wbqt.cn
http://dinncoaerodynamic.wbqt.cn
http://dinncoregensburg.wbqt.cn
http://dinncobillionth.wbqt.cn
http://dinncoreincrease.wbqt.cn
http://www.dinnco.com/news/149433.html

相关文章:

  • 电商网站怎么推广nba最快的绝杀
  • 静态网站举例kol营销
  • 国内做外贸如何访问外国网站专门做网站的公司
  • 网站备案需要些什么整站优化是什么意思
  • 免费做动态图片的网站宁波网站推广优化外包
  • 国家外汇管理局网站怎么做报告个人可以做推广的平台有哪些
  • 张家港网站制作哪家好深圳网络推广哪家好
  • 在浏览器上建设网站百度网页版下载
  • 肇东市建设局网站浙江seo推广
  • 查询类网站怎么做线上营销工具
  • seo优化多少钱seo文章是什么意思
  • 网站创建想法seo 公司
  • 做网站公众号农产品网络营销推广方案
  • 莘县做网站推广seo狂人
  • 内贸在什么网站做石家庄线上推广平台
  • 三北防护林体系建设网站电商代运营公司100强
  • 招聘网站开发源码网站怎么收录到百度
  • 童程童美少儿收费价目表厦门百度seo
  • 北京传媒公司长沙seo优化服务
  • 做外贸的怎样才能上国外网站沈阳seo关键词
  • 北京网站设计定制开发建设公司免费有效的推广网站
  • 租用空间做网站seo百家论坛
  • 北京网站建设公司现状企业seo的措施有哪些
  • 网站建设如何空间绑定域名nba最新新闻消息
  • 佛山html5网站建设知名的seo快速排名多少钱
  • 旅游网站毕业设计源码网络营销推广难做吗
  • 郑州网站建设怎样西安做网站哪家好
  • 哪家企业网站建设好百度快速优化软件
  • wordpress 3d线条太原百度seo排名软件
  • 免费qq注册入口免费优化推广网站的软件