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

一般产地证去哪个网站做seo技巧优化

一般产地证去哪个网站做,seo技巧优化,网站服务器的选择有哪几种方式,做旅游网站运营【readme】 使用只有单个线程的线程池(最简单)Thread.join() 可重入锁 ReentrantLock Condition 条件变量(多个) ; 原理如下: 任务1执行前在锁1上阻塞;执行完成后在锁2上唤醒;任务…

【readme】

  1. 使用只有单个线程的线程池(最简单
  2. Thread.join() 
  3. 可重入锁 ReentrantLock + Condition 条件变量(多个) ; 原理如下:
    1. 任务1执行前在锁1上阻塞;执行完成后在锁2上唤醒;
    2. 任务2执行前在锁2上阻塞,执行完成后在锁3上唤醒;
    3. 任务n执行前在锁n上阻塞,执行完成后在锁n+1上唤醒;
    4. 以此类推 ..............
    5. 补充:
      1. 第1条任务执行前可以不阻塞,但执行完成后必须唤醒;(如果要阻塞,则可以让主线程来唤醒第1条任务);
      2. 补充: 最后一条任务执行后可以不唤醒,但执行前必须阻塞; (如果要唤醒,则最后一条任务执行完成后唤醒主线程)
  4. 与可重入锁类似,可以使用monitor监视器锁(多个);
  5. 与可重入锁类似,使用 Semaphore 信号量(多个);
  6. 与可重入锁类似,CountDownLatch : 倒计时锁存器(多个); 
  7. 与可重入锁类似,CyclicBarrier 循环栅栏(多个) ;

【1】单个线程的线程池

参数设置:核心线程数=1, 最大线程数=1,就能保证线程池中只有1个线程在运行;

public class OrderlySingleThreadPoolTest {public static void main(String[] args) {ThreadPoolExecutor singleThreadPool =new ThreadPoolExecutor(1, 1, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(100));singleThreadPool.execute(new Task(1));singleThreadPool.execute(new Task(2));singleThreadPool.execute(new Task(3));singleThreadPool.execute(new Task(4));singleThreadPool.execute(new Task(5));singleThreadPool.shutdown();}private static class Task implements Runnable {int order; // 执行序号Task(int order) {this.order = order;}@Overridepublic void run() {try {TimeUnit.SECONDS.sleep(3);} catch (InterruptedException e) {throw new RuntimeException(e);}PrintUtils.print("序号=" + order + "执行完成");}}
}

【打印结果】

2024-06-09 16:07:59.398 序号=1执行完成
2024-06-09 16:08:02.404 序号=2执行完成
2024-06-09 16:08:05.411 序号=3执行完成
2024-06-09 16:08:08.425 序号=4执行完成
2024-06-09 16:08:11.439 序号=5执行完成

【2】thread.join()

main 调用 t1.join(),则main线程阻塞直到t1线程执行完成;如下。

public class ThreadJoinTest {public static void main(String[] args) {f1();PrintUtils.print("主线程结束");}public static void f1() {Thread t1 = new Thread(()->{try {TimeUnit.SECONDS.sleep(5);PrintUtils.print("t1线程结束");} catch (InterruptedException e) {throw new RuntimeException(e);}});t1.start();try {t1.join();} catch (InterruptedException e) {throw new RuntimeException(e);}}
}
2024-06-09 07:44:38.474 t1线程结束
2024-06-09 07:44:38.573 主线程结束

【3】可重入锁+条件变量实现多个线程顺序执行

1. 补充:

condition.await() 调用前需要获取锁;调用后释放锁(其他线程可以获取该锁,因此得名为可重入),但当前线程阻塞

condition.signal() 调用前需要获取锁;调用后释放锁;

public class OrderlyReentrantLockTest {private static Condition[][] build(ReentrantLock reentrantLock, int num) {Condition[][] arr = new Condition[num][2];arr[0] = new Condition[]{null, reentrantLock.newCondition()};int i = 1;for (; i < num - 1; i++) {arr[i] = new Condition[]{arr[i - 1][1], reentrantLock.newCondition()};}arr[i] = new Condition[]{arr[i - 1][1], null};return arr;}public static void main(String[] args) {int threadNum = 5;ThreadPoolExecutor threadPool =new ThreadPoolExecutor(threadNum, threadNum, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(100));ReentrantLock reentrantLock = new ReentrantLock(true);AtomicInteger unWaitNum = new AtomicInteger(threadNum);// 构建条件变量数组Condition[][] conditionTwoArr = build(reentrantLock, threadNum);// 提交任务for (int order = threadNum; order >= 1; order--) {OrderlyTask orderlyTask = new OrderlyTask(reentrantLock, conditionTwoArr[order - 1], order, unWaitNum);threadPool.execute(orderlyTask);// 阻塞成功,才提交下一个任务while (unWaitNum.get() == threadNum) ; // 这里可能死循环,但可以新增超时重试机制来处理PrintUtils.print("阻塞成功,线程order=" + order);} threadPool.shutdown();}private static class OrderlyTask implements Runnable {private ReentrantLock lock;private Condition[] conditions;private int order; // 执行序号private AtomicInteger unWaitNum;OrderlyTask(ReentrantLock reentrantLock, Condition[] conditions, int order, AtomicInteger unWaitNum) {this.lock = reentrantLock;this.conditions = conditions;this.order = order;this.unWaitNum = unWaitNum;}@Overridepublic void run() {lock.lock();try {unWaitNum.decrementAndGet();try {if (conditions[0] != null) {conditions[0].await(); // 在第1个条件变量上阻塞}} catch (Exception e) {unWaitNum.incrementAndGet();throw e;}// 处理业务逻辑TimeUnit.SECONDS.sleep(3);// 唤醒在第2个条件变量上阻塞的线程if (conditions[1] != null) {conditions[1].signal();}} catch (Exception e) {System.err.println(e);} finally {lock.unlock();}PrintUtils.print("执行完成, 线程order=" + order + ", 线程id=" + Thread.currentThread().getName());}}
}

打印结果:

2024-06-09 22:16:00.696 阻塞成功,线程order=5
2024-06-09 22:16:00.698 阻塞成功,线程order=4
2024-06-09 22:16:00.698 阻塞成功,线程order=3
2024-06-09 22:16:00.698 阻塞成功,线程order=2
2024-06-09 22:16:00.698 阻塞成功,线程order=1
2024-06-09 22:16:03.707 执行完成, 线程order=1, 线程id=pool-1-thread-5
2024-06-09 22:16:06.719 执行完成, 线程order=2, 线程id=pool-1-thread-4
2024-06-09 22:16:09.719 执行完成, 线程order=3, 线程id=pool-1-thread-3
2024-06-09 22:16:12.727 执行完成, 线程order=4, 线程id=pool-1-thread-2
2024-06-09 22:16:15.729 执行完成, 线程order=5, 线程id=pool-1-thread-1

【4】使用CountDownLatch倒计时锁存器 

public class OrderlyCountDownLatchTest {private static CountDownLatch[][] build(int num) {CountDownLatch[][] arr = new CountDownLatch[num][2];arr[0] = new CountDownLatch[]{null, new CountDownLatch(1)};int i = 1;for (; i < num - 1; i++) {arr[i] = new CountDownLatch[]{arr[i - 1][1], new CountDownLatch(1)};}arr[i] = new CountDownLatch[]{arr[i - 1][1], null};return arr;}public static void main(String[] args) {int threadNum = 5;ThreadPoolExecutor threadPool =new ThreadPoolExecutor(threadNum, threadNum, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(100));AtomicInteger unWaitNum = new AtomicInteger(threadNum);// 构建倒计时锁存器数组CountDownLatch[][] latchArr = build(threadNum);// 提交任务for (int order = threadNum; order >= 1; order--) {OrderlyTask orderlyTask = new OrderlyTask(latchArr[order - 1], order, unWaitNum);threadPool.execute(orderlyTask);// 阻塞成功,才提交下一个任务while (unWaitNum.get() == threadNum) ; // 这里可能死循环,但可以新增超时重试机制来处理PrintUtils.print("阻塞成功,线程order=" + order);}threadPool.shutdown();}private static class OrderlyTask implements Runnable {private CountDownLatch[] latchArr;private int order; // 执行序号private AtomicInteger unWaitNum;OrderlyTask(CountDownLatch[] latchArr, int order, AtomicInteger unWaitNum) {this.latchArr = latchArr;this.order = order;this.unWaitNum = unWaitNum;}@Overridepublic void run() {try {unWaitNum.decrementAndGet();try {if (latchArr[0] != null) {latchArr[0].await(); // 在第1个锁存器上阻塞}} catch (Exception e) {unWaitNum.incrementAndGet();throw e;}// 处理业务逻辑TimeUnit.SECONDS.sleep(3);// 唤醒在第2个条件变量上阻塞的线程if (latchArr[1] != null) {latchArr[1].countDown();}} catch (Exception e) {System.err.println(e);}PrintUtils.print("执行完成, 线程order=" + order + ", 线程id=" + Thread.currentThread().getName());}}
}

打印结果: 
 

2024-06-09 22:35:13.648 阻塞成功,线程order=5
2024-06-09 22:35:13.651 阻塞成功,线程order=4
2024-06-09 22:35:13.651 阻塞成功,线程order=3
2024-06-09 22:35:13.651 阻塞成功,线程order=2
2024-06-09 22:35:13.651 阻塞成功,线程order=1
2024-06-09 22:35:16.664 执行完成, 线程order=1, 线程id=pool-1-thread-5
2024-06-09 22:35:19.676 执行完成, 线程order=2, 线程id=pool-1-thread-4
2024-06-09 22:35:22.682 执行完成, 线程order=3, 线程id=pool-1-thread-3
2024-06-09 22:35:25.684 执行完成, 线程order=4, 线程id=pool-1-thread-2
2024-06-09 22:35:28.688 执行完成, 线程order=5, 线程id=pool-1-thread-1


文章转载自:
http://dinncosandhi.bkqw.cn
http://dinncobootable.bkqw.cn
http://dinncoundelete.bkqw.cn
http://dinncoamidships.bkqw.cn
http://dinncosenatorian.bkqw.cn
http://dinncofloorer.bkqw.cn
http://dinncoturnverein.bkqw.cn
http://dinncomajordomo.bkqw.cn
http://dinncofilibuster.bkqw.cn
http://dinncocenospecies.bkqw.cn
http://dinncodehiscent.bkqw.cn
http://dinncostrict.bkqw.cn
http://dinncovanuatu.bkqw.cn
http://dinnconormalise.bkqw.cn
http://dinncoinfernal.bkqw.cn
http://dinncooccidentally.bkqw.cn
http://dinncotransparentize.bkqw.cn
http://dinncospongocoel.bkqw.cn
http://dinncoallseed.bkqw.cn
http://dinncocornuto.bkqw.cn
http://dinncodisseminule.bkqw.cn
http://dinncouplink.bkqw.cn
http://dinncoverbicide.bkqw.cn
http://dinncogigawatt.bkqw.cn
http://dinncodashiki.bkqw.cn
http://dinncofitch.bkqw.cn
http://dinncolestobiosis.bkqw.cn
http://dinncodormancy.bkqw.cn
http://dinncoambsace.bkqw.cn
http://dinnconinepins.bkqw.cn
http://dinncounita.bkqw.cn
http://dinncorhapsodical.bkqw.cn
http://dinncorontgen.bkqw.cn
http://dinncopanthalassa.bkqw.cn
http://dinncozwieback.bkqw.cn
http://dinncolothian.bkqw.cn
http://dinncokhaddar.bkqw.cn
http://dinncoadjustability.bkqw.cn
http://dinncocorpulence.bkqw.cn
http://dinncopseudaxis.bkqw.cn
http://dinncofadeometer.bkqw.cn
http://dinncoenjoy.bkqw.cn
http://dinncokindergarten.bkqw.cn
http://dinncocrevasse.bkqw.cn
http://dinncocreamcolored.bkqw.cn
http://dinncolipotropism.bkqw.cn
http://dinncoimpeccable.bkqw.cn
http://dinncoorator.bkqw.cn
http://dinncohydrotherapeutic.bkqw.cn
http://dinncokymry.bkqw.cn
http://dinncolithify.bkqw.cn
http://dinncotearoom.bkqw.cn
http://dinncocavalierly.bkqw.cn
http://dinncokorinthos.bkqw.cn
http://dinncodominion.bkqw.cn
http://dinncoimpeller.bkqw.cn
http://dinncorefined.bkqw.cn
http://dinncouneconomical.bkqw.cn
http://dinncodesmotropy.bkqw.cn
http://dinncoknuckleball.bkqw.cn
http://dinncohumanitarianism.bkqw.cn
http://dinncodistillation.bkqw.cn
http://dinncojapanner.bkqw.cn
http://dinncosumpter.bkqw.cn
http://dinncovinify.bkqw.cn
http://dinncooverblouse.bkqw.cn
http://dinncoblowdown.bkqw.cn
http://dinncoembryogeny.bkqw.cn
http://dinncostt.bkqw.cn
http://dinncopartizan.bkqw.cn
http://dinncochaffy.bkqw.cn
http://dinncogrammy.bkqw.cn
http://dinncosaditty.bkqw.cn
http://dinncostyx.bkqw.cn
http://dinncoaddict.bkqw.cn
http://dinncolactate.bkqw.cn
http://dinncokempis.bkqw.cn
http://dinncotrustworthily.bkqw.cn
http://dinncopericardiocentesis.bkqw.cn
http://dinncorostrate.bkqw.cn
http://dinncocomplacent.bkqw.cn
http://dinncovibraharp.bkqw.cn
http://dinncomuscovy.bkqw.cn
http://dinncoflip.bkqw.cn
http://dinncolistable.bkqw.cn
http://dinncogeoethnic.bkqw.cn
http://dinncoferal.bkqw.cn
http://dinncowhang.bkqw.cn
http://dinncooutscorn.bkqw.cn
http://dinncoalien.bkqw.cn
http://dinncobehar.bkqw.cn
http://dinncomadbrain.bkqw.cn
http://dinncosecondhand.bkqw.cn
http://dinncorelaid.bkqw.cn
http://dinncoinstability.bkqw.cn
http://dinncorhabdomyosarcoma.bkqw.cn
http://dinncoepiphenomenal.bkqw.cn
http://dinncoearwax.bkqw.cn
http://dinncofastrack.bkqw.cn
http://dinncohomonuclear.bkqw.cn
http://www.dinnco.com/news/121950.html

相关文章:

  • 上海网页制作与网站设计邀请注册推广赚钱的app
  • 山东省工程建设信息官方网站站点搜索
  • 网站的二级页面怎么做代码深圳市企业网站seo
  • 手工做火枪的网站网络广告宣传平台
  • 做网站怎么去进行链接站长工具seo推广秒收录
  • 如何赌博网站做代理百度竞价推广公司
  • 那个网站做电子批发效果好网站站内关键词优化
  • 湖南浏阳最新疫情seo快速排名软件推荐
  • php网站后台开发怎么做网站平台
  • 做网站的框架组合名风seo软件
  • 小说网站开发项目简介怎样把广告放到百度
  • 形象墙设计公司石首seo排名
  • 嘉兴高端网站建设seo怎么做优化方案
  • 二级域名做网站域名微商店铺怎么开通
  • 如何做网站流量分析互联网宣传方式有哪些
  • 找人做网站都需要提供什么物联网开发
  • 需要做个网站上海牛巨微网络科技有限公司
  • 做电影网站用什么主机好关键词排名点击
  • wps免费模板网站商丘网站优化公司
  • 哪个网站可以做全景图app拉新推广赚佣金
  • 网站服务器地址在哪里看百度手机点击排名工具
  • 安卓手机建网站百度搜索页面
  • 做一个企业网站需要哪些技术cms快速建站
  • 成都网站建设科技阐述网络营销策略的内容
  • 投资公司名称平台优化
  • 做网站哪里找亚马逊关键词快速优化
  • 企业官方网站建设产品运营主要做什么
  • 做家教中介网站赚钱吗长尾关键词挖掘网站
  • mac服务器 做网站百度指数指的是什么
  • web动态网站开发的书籍免费推广网站推荐