教育网站颜色idea网站开发教程

张小明 2026/3/13 0:48:10
教育网站颜色,idea网站开发教程,建立自我追求无我什么意思,建一个网站要多久预备知识、各种同步工具synchronized wait/notify 概括#xff1a;Java内置的最基础的线程同步机制#xff0c;基于对象监视器实现。 用途#xff1a;用于简单的线程互斥和等待通知机制#xff0c;如传统的生产者-消费者问题。CountDownLatch 概括#xff1a;一次性的事件…预备知识、各种同步工具synchronized wait/notify概括Java内置的最基础的线程同步机制基于对象监视器实现。用途用于简单的线程互斥和等待通知机制如传统的生产者-消费者问题。CountDownLatch概括一次性的事件等待器通过倒计时控制线程执行顺序。用途等待多个并行任务全部完成后再继续执行如初始化完成后启动主应用。CompletableFuture概括声明式的异步编程框架支持任务链式编排和组合。用途优雅地编排多个异步任务处理复杂的异步依赖关系如并行调用多个微服务。Semaphore概括基于许可证的资源控制器限制并发访问数量。用途控制对有限资源的并发访问如数据库连接池、限流器。ReentrantLock Condition概括功能更丰富的显式锁提供比synchronized更灵活的控制。用途需要高级同步特性的场景如可中断锁、公平锁、多个等待条件。BlockingQueueBlockingQueue 是 Java 并发包中开箱即用的 “生产者 - 消费者” 解决方案本质是对 ReentrantLock Condition 的高级封装比如 ArrayBlockingQueue 底层就是用这组工具实现的一、按序打印Leetcode 1114)给你一个类publicclassFoo{publicvoidfirst(){print(first);}publicvoidsecond(){print(second);}publicvoidthird(){print(third);}}三个不同的线程 A、B、C 将会共用一个 Foo 实例。线程 A 将会调用 first() 方法线程 B 将会调用 second() 方法线程 C 将会调用 third() 方法请设计修改程序以确保 second() 方法在 first() 方法之后被执行third() 方法在 second() 方法之后被执行。classFoo{publicFoo(){}publicvoidfirst(RunnableprintFirst)throwsInterruptedException{printFirst.run();}publicvoidsecond(RunnableprintSecond)throwsInterruptedException{printSecond.run();}publicvoidthird(RunnableprintThird)throwsInterruptedException{printThird.run();}}方法一忙等待优点简单缺点空转CPU可能会死循环classFoo{privatevolatileintx0;publicFoo(){}publicvoidfirst(RunnableprintFirst)throwsInterruptedException{printFirst.run();x;}publicvoidsecond(RunnableprintSecond)throwsInterruptedException{while(x!1){}printSecond.run();x;}publicvoidthird(RunnableprintThird)throwsInterruptedException{while(x!2){}printThird.run();}}1这里x因为不是原子性操作如果有多个线程同时调用first/second/third 会出现问题2while循环里面可以加Thread.yield() 减少自旋的 CPU 消耗classFoo{privateAtomicIntegerxnewAtomicInteger(0);publicFoo(){}publicvoidfirst(RunnableprintFirst)throwsInterruptedException{printFirst.run();x.incrementAndGet();}publicvoidsecond(RunnableprintSecond)throwsInterruptedException{while(x.get()!1){Thread.yield();}printSecond.run();x.incrementAndGet();}publicvoidthird(RunnableprintThird)throwsInterruptedException{while(x.get()!2){Thread.yield();}printThird.run();}}方法二synchronized wait/notifyclassFoo{privateintx0;privatefinalObjectlocknewObject();publicFoo(){}publicvoidfirst(RunnableprintFirst)throwsInterruptedException{synchronized(lock){printFirst.run();x;lock.notifyAll();}}publicvoidsecond(RunnableprintSecond)throwsInterruptedException{synchronized(lock){while(x!1){lock.wait();}printSecond.run();x;lock.notifyAll();}}publicvoidthird(RunnableprintThird)throwsInterruptedException{synchronized(lock){while(x!2){lock.wait();}printThird.run();lock.notifyAll();}}}方法三CountDownLatchclassFoo{privatefinalCountDownLatchlatch1newCountDownLatch(1);privatefinalCountDownLatchlatch2newCountDownLatch(1);publicFoo(){}publicvoidfirst(RunnableprintFirst)throwsInterruptedException{printFirst.run();latch1.countDown();}publicvoidsecond(RunnableprintSecond)throwsInterruptedException{latch1.await();printSecond.run();latch2.countDown();}publicvoidthird(RunnableprintThird)throwsInterruptedException{latch2.await();printThird.run();}}方法四SemaphoreclassFoo{privatefinalSemaphoresem2newSemaphore(0);privatefinalSemaphoresem3newSemaphore(0);publicFoo(){}publicvoidfirst(RunnableprintFirst)throwsInterruptedException{printFirst.run();sem2.release();}publicvoidsecond(RunnableprintSecond)throwsInterruptedException{sem2.acquire();printSecond.run();sem3.release();}publicvoidthird(RunnableprintThird)throwsInterruptedException{sem3.acquire();printThird.run();}}方法五ReentrantLockConditionclassFoo{privatefinalLocklocknewReentrantLock();privatefinalConditioncond1lock.newCondition();privatefinalConditioncond2lock.newCondition();privateintflag0;publicFoo(){}publicvoidfirst(RunnableprintFirst)throwsInterruptedException{lock.lock();try{printFirst.run();flag;cond1.signal();}finally{lock.unlock();}}publicvoidsecond(RunnableprintSecond)throwsInterruptedException{lock.lock();try{while(flag!1){cond1.await();}printSecond.run();flag;cond2.signal();}finally{lock.unlock();}}publicvoidthird(RunnableprintThird)throwsInterruptedException{lock.lock();try{while(flag!2){cond2.await();}printThird.run();}finally{lock.unlock();}}}方法六CompletableFutureclassFoo{privateCompletableFutureVoidcf1newCompletableFuture();privateCompletableFutureVoidcf2newCompletableFuture();publicvoidfirst(RunnableprintFirst){printFirst.run();cf1.complete(null);// 信号first完成了}publicvoidsecond(RunnableprintSecond){cf1.join();// 阻塞等待cf1完成printSecond.run();cf2.complete(null);// 信号second完成了}publicvoidthird(RunnableprintThird){cf2.join();// 阻塞等待cf2完成printThird.run();}}二、交替打印Leetcode 1115)给你一个类classFooBar{publicvoidfoo(){for(inti0;in;i){print(foo);}}publicvoidbar(){for(inti0;in;i){print(bar);}}}两个不同的线程将会共用一个 FooBar 实例线程 A 将会调用 foo() 方法而线程 B 将会调用 bar() 方法请设计修改程序以确保 “foobar” 被输出 n 次。方法一忙等待classFooBar{privateintn;publicFooBar(intn){this.nn;}privatevolatilebooleanstatetrue;publicvoidfoo(RunnableprintFoo)throwsInterruptedException{for(inti0;in;){if(state){printFoo.run();i;statefalse;}else{Thread.yield();}}}publicvoidbar(RunnableprintBar)throwsInterruptedException{for(inti0;in;){if(!state){printBar.run();i;statetrue;}else{Thread.yield();}}}}方法二synchronized wait/notifyclassFooBar{privateintn;publicFooBar(intn){this.nn;}privatebooleanstatetrue;privatefinalObjectlocknewObject();publicvoidfoo(RunnableprintFoo)throwsInterruptedException{for(inti0;in;i){synchronized(lock){while(!state){lock.wait();}printFoo.run();statefalse;lock.notifyAll();}}}publicvoidbar(RunnableprintBar)throwsInterruptedException{for(inti0;in;i){synchronized(lock){while(state){lock.wait();}printBar.run();statetrue;lock.notifyAll();}}}}方法三SemaphoreclassFooBar{privateintn;publicFooBar(intn){this.nn;}privatefinalSemaphoresem1newSemaphore(1);privatefinalSemaphoresem2newSemaphore(0);publicvoidfoo(RunnableprintFoo)throwsInterruptedException{for(inti0;in;i){sem1.acquire();printFoo.run();sem2.release();}}publicvoidbar(RunnableprintBar)throwsInterruptedException{for(inti0;in;i){sem2.acquire();printBar.run();sem1.release();}}}方法四ReentrantLockConditionclassFooBar{privateintn;publicFooBar(intn){this.nn;}privatefinalLocklocknewReentrantLock();privatefinalConditioncondlock.newCondition();privatebooleanflagtrue;publicvoidfoo(RunnableprintFoo)throwsInterruptedException{for(inti0;in;i){lock.lock();try{while(!flag){cond.await();}printFoo.run();flagfalse;cond.signal();}finally{lock.unlock();}}}publicvoidbar(RunnableprintBar)throwsInterruptedException{for(inti0;in;i){lock.lock();try{while(flag){cond.await();}printBar.run();flagtrue;cond.signal();}finally{lock.unlock();}}}}三、打印零与奇偶数
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

钓鱼网站网站怎么做ie浏览器网址入口

简介 大模型训练分为预训练和微调两阶段。预训练利用大量未标记数据学习通用语言特征;微调则通过少量标记数据使模型适应特定任务。微调技术可分为全量微调(成本高效果好)和高效微调(如Adapter、LoRA,成本低效果好);也可按目标分为监督微调、…

张小明 2026/3/5 2:36:11 网站建设

前端网站推荐企业微信开发者工具

硅谷可控大模型智能体 AI 关键技术 Control is enforced at runtime, not assumed at training time. 硅谷可控大模型智能体 AI 技术以大模型智能体第一性原理为核心,融合硅谷专家多年企业级智能体系统实践,以 Controllable AI 为纲,打通 Ag…

张小明 2026/3/5 2:36:45 网站建设

十大网站在线观看青岛建立网站电话

本地部署HunyuanVideo-Foley:AI自动配音效全教程 你有没有试过剪辑完一段视频,回放时却发现——画面有张力,声音却像真空里播放? 明明是疾风骤雨的追逐戏,背景音却是死寂一片; 主角一脚踹开门,“…

张小明 2026/3/5 2:36:12 网站建设

网站做的文字乱码网站建设费用兴田德润团队

我们来逐步推理:1. 理解条件 “c在ab之间”意思是 a、b、c三人的相对顺序必须是 a-c-b 或者 b-c-a(即c在a和b正中间),并且它们三个人之间不一定相邻,但整体相对顺序要满足中间的是c。 条件:c的位置在a与b的…

张小明 2026/3/5 2:36:13 网站建设