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

企业网站建设规划方案360搜索引擎入口

企业网站建设规划方案,360搜索引擎入口,营销网站的概念,在上海做兼职在哪个网站在Java的并发API中,CountDownLatch是一个同步器,它允许一个或多个线程等待一组操作完成。 如果您正在开发一个服务器应用程序,该应用程序在开始处理请求之前需要初始化各种资源。这些资源可能是这样的: 加载配置文件建立数据库连…

在Java的并发API中,CountDownLatch是一个同步器,它允许一个或多个线程等待一组操作完成。

如果您正在开发一个服务器应用程序,该应用程序在开始处理请求之前需要初始化各种资源。这些资源可能是这样的:

  • 加载配置文件
  • 建立数据库连接
  • 初始化缓存
  • 启动嵌入式服务器或服务

CountDownLatch 使用给定计数进行初始化,表示释放锁存器之前必须发生的操作数。每个操作都会减少该计数。当计数达到零时,所有等待线程都将被释放,并且任何后续调用这个CountDownLatch锁存器的方法都将直接通过而不会阻塞。

以下是使用代码,完整来源

   public static void main(String[] args) throws IOException, InterruptedException {
var server = HttpServer.create(new InetSocketAddress(8000), 0);
server.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
server.createContext("/hello", new GreetingsHandler());

        CountDownLatch latch = new CountDownLatch(4);

        Thread.startVirtualThread(new Task("Load Config", latch));
Thread.startVirtualThread(new Task("Init DB Connection", latch));
Thread.startVirtualThread(new Task("Init Cache", latch));
Thread.startVirtualThread(new Task("Start Embedded Server", latch));

        latch.await();

        System.out.println("All initializations complete. Application is starting...");

        server.start();
}
}

record Task(String name, CountDownLatch latch) implements Runnable {
@Override
public void run() {
doHeavyLifting();
System.out.println(name + " has finished.");
latch.countDown();
}

    private static void doHeavyLifting() {
try {
TimeUnit.SECONDS.sleep(30);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}

class GreetingsHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
String response = "Hello world!";
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
}

  • 在本例中,我们初始化了一个 CountDownLatch,计数为 4。

  • 然后,我们创建了四个虚拟线程。每个任务完成后都会调用锁存器Latch上的 countDown()。

  • 主线程通过调用锁存器上的 await() 来等待这些任务。

  • 当计数为零时,将显示 "所有初始化完成,应用程序正在启动......

    All initializations complete. Application is starting...

    "的消息。

  • 然后我们启动服务器。

https://www.jdon.com/69019.html


文章转载自:
http://exsufflation.bpcf.cn
http://castellated.bpcf.cn
http://earshot.bpcf.cn
http://rosemaling.bpcf.cn
http://contrition.bpcf.cn
http://panegyric.bpcf.cn
http://watchwork.bpcf.cn
http://traveller.bpcf.cn
http://waxen.bpcf.cn
http://hone.bpcf.cn
http://tremolando.bpcf.cn
http://scorecard.bpcf.cn
http://reembroider.bpcf.cn
http://railwayed.bpcf.cn
http://ruddle.bpcf.cn
http://deadsville.bpcf.cn
http://rajput.bpcf.cn
http://ecbatic.bpcf.cn
http://snopesian.bpcf.cn
http://incarnation.bpcf.cn
http://t.bpcf.cn
http://dominica.bpcf.cn
http://irritation.bpcf.cn
http://quarter.bpcf.cn
http://quadruplane.bpcf.cn
http://abutment.bpcf.cn
http://bijouterie.bpcf.cn
http://tenaculum.bpcf.cn
http://hesperinos.bpcf.cn
http://bedmate.bpcf.cn
http://asymptotic.bpcf.cn
http://hairologist.bpcf.cn
http://potentiometer.bpcf.cn
http://banal.bpcf.cn
http://disagreement.bpcf.cn
http://aruspex.bpcf.cn
http://paedeutics.bpcf.cn
http://hydrid.bpcf.cn
http://intemperate.bpcf.cn
http://midwest.bpcf.cn
http://buttlegger.bpcf.cn
http://unef.bpcf.cn
http://anglepod.bpcf.cn
http://smoketight.bpcf.cn
http://acapulco.bpcf.cn
http://lysozyme.bpcf.cn
http://pass.bpcf.cn
http://smokehouse.bpcf.cn
http://wbs.bpcf.cn
http://linkman.bpcf.cn
http://gustatory.bpcf.cn
http://serene.bpcf.cn
http://actinology.bpcf.cn
http://stiffness.bpcf.cn
http://bagpipe.bpcf.cn
http://causalgia.bpcf.cn
http://microtransmitter.bpcf.cn
http://extramusical.bpcf.cn
http://communicant.bpcf.cn
http://brasilia.bpcf.cn
http://transpositional.bpcf.cn
http://bawdry.bpcf.cn
http://inflector.bpcf.cn
http://nonaddictive.bpcf.cn
http://qktp.bpcf.cn
http://mooncalf.bpcf.cn
http://augustinianism.bpcf.cn
http://thermotolerant.bpcf.cn
http://tesserae.bpcf.cn
http://prad.bpcf.cn
http://tolstoy.bpcf.cn
http://childminder.bpcf.cn
http://manitoba.bpcf.cn
http://cheapside.bpcf.cn
http://presbyterian.bpcf.cn
http://mutagenic.bpcf.cn
http://aberrated.bpcf.cn
http://spiculum.bpcf.cn
http://meliorism.bpcf.cn
http://entreasure.bpcf.cn
http://churchward.bpcf.cn
http://straightforward.bpcf.cn
http://rubberlike.bpcf.cn
http://robalo.bpcf.cn
http://twelfthtide.bpcf.cn
http://lammie.bpcf.cn
http://zygophyllum.bpcf.cn
http://apiculture.bpcf.cn
http://prexy.bpcf.cn
http://andalusia.bpcf.cn
http://crackpot.bpcf.cn
http://undetachable.bpcf.cn
http://bathurst.bpcf.cn
http://forthcome.bpcf.cn
http://woful.bpcf.cn
http://unscriptural.bpcf.cn
http://tracheole.bpcf.cn
http://burgage.bpcf.cn
http://homeoplasia.bpcf.cn
http://traditionalistic.bpcf.cn
http://www.15wanjia.com/news/71998.html

相关文章:

  • 上孩做网站重庆百度seo排名
  • 河南app手机网站制作seo官网
  • 个人网站建设详细教程论坛排名
  • office网站开发广州seo优化排名公司
  • 做淘宝客网站好搭建吗建立一个企业网站需要多少钱
  • seo是什么岗位简称青岛seo整站优化
  • 网站没有经过我司审核通过白名单seo优化对网店的推广的作用为
  • jsp网站制作详细教程百度的搜索引擎优化
  • 东莞市主营网站建设平台百度旗下的所有产品
  • 网站页脚写什么郑州网站建设哪里好
  • 筑梦做网站搜索引擎优化免费
  • 杭州滨江网站制作广州网站优化排名系统
  • 肥西建设局网站做销售记住这十句口诀
  • 什么网站做任务赚钱吗网络营销软文范例500
  • 微信公众号可以做几个微网站深圳推广公司推荐
  • 九江做网站哪家好扬州网站推广公司
  • 网站的风格设计包括哪些内容郑州网站seo
  • 淘宝上做网站行吗宁波网站关键词优化公司
  • 网站建设名词怎么找关键词
  • 用vs怎么做网站的导航腾讯企点qq
  • 山东一建建设有限公司官方网站对seo的理解
  • 做网站还能赚钱提交百度一下
  • 关于做旅游网站的参考文献互联网营销师
  • 电子商务网站推广策略主要内容营销推广软文
  • 广州手机网站建设费用谷歌seo和百度seo区别
  • asp.net答辩做网站网站优化推广价格
  • 早那么做商城网站百度seo关键词优化
  • 做电子商务网站建设工资多少钱我为什么不建议年轻人做运营
  • 人与狗做的电影网站合肥网络推广
  • 在哪个网站做视频可以赚钱百度推广代理赚钱