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

winserver2008上用iis发布网站江苏省建设厅网站 投诉

winserver2008上用iis发布网站,江苏省建设厅网站 投诉,wordpress群站,深圳极速网站建设公司编写一个Java程序#xff0c;其中包含三个线程: 厨师(Chef)、服务员(Waiter)和顾客(Customer)。他们的行动如下: 厨师准备菜肴#xff0c;每次准备一个。服务员等待菜肴准备好#xff0c;然后将其送到顾客那里。顾客等待服务员送来菜看后才开始吃。所有三个角色应该循环进行…编写一个Java程序其中包含三个线程: 厨师(Chef)、服务员(Waiter)和顾客(Customer)。他们的行动如下: 厨师准备菜肴每次准备一个。服务员等待菜肴准备好然后将其送到顾客那里。顾客等待服务员送来菜看后才开始吃。所有三个角色应该循环进行他们的行为直到指定数量的菜肴被制作和消费完。使用wait()和notify0)确保线程间正确的通信和同步。 package com;/*** program: RestaurantDemo* description: 餐厅类* author: Casey Hu* create: 2023-12-18 16:13**/public class Restaurant {public static void main(String[] args) throws InterruptedException {Chef chef new Chef();Waiter waiter new Waiter(chef);Customer customer new Customer(waiter);chef.start();waiter.start();customer.start();chef.join();waiter.join();customer.join();System.out.println(餐厅关闭.);}static class Chef extends Thread {private final int MAX_FOOD 10;private int foodCount 0;private boolean isFinished false;Overridepublic void run() {while (!isFinished) {try {// 厨师准备菜肴System.out.println(厨师准备菜肴...);Thread.sleep(1000);// 菜肴准备好后唤醒服务员foodCount;synchronized (this) {this.notify();}if (foodCount MAX_FOOD) {isFinished true;}} catch (InterruptedException e) {e.printStackTrace();}}}}static class Waiter extends Thread {private Chef chef;public Waiter(Chef chef) {this.chef chef;}Overridepublic void run() {while (!chef.isFinished) {try {synchronized (chef) {// 等待厨师准备菜肴chef.wait();}// 将菜肴送到顾客那里System.out.println(服务员将菜肴送到顾客那里...);Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}}}}static class Customer extends Thread {private Waiter waiter;public Customer(Waiter waiter) {this.waiter waiter;}Overridepublic void run() {while (!waiter.chef.isFinished) {try {// 等待服务员送来菜肴Thread.sleep(1000);// 开始吃菜肴System.out.println(顾客开始吃菜肴...);// 通知服务员可以送下一道菜了synchronized (waiter.chef) {waiter.chef.notify();}} catch (InterruptedException e) {e.printStackTrace();}}}} } 上述代码中启动了三个子线程厨师线程、服务员线程和顾客线程。厨师线程使用foodCount计数器来记录制作的菜肴数量并使用synchronized关键字确保线程安全。每当它制作好一道菜肴后它唤醒等待的服务员线程。 服务员线程使用synchronized和wait()方法等待厨师线程准备好菜肴。一旦收到通知它将菜肴送到顾客那里。 顾客线程使用synchronized关键字和notify()方法通知服务员准备下一道菜肴并在接收到菜肴后开始吃。 主线程使用join()方法等待所有子线程完成。 这个示例使用了Java中的核心多线程机制(Thread、Runnable、synchronized、wait()和notify()等)来模拟餐厅的运作。 运行结果 但是有一段代码 public class Restaurant {private static final int MAX_FOOD 10;private static final Object lock new Object();private static int foodCount 0;public static void main(String[] args) {Chef chef new Chef();Waiter waiter new Waiter();Customer customer new Customer();chef.start();waiter.start();customer.start();}static class Chef extends Thread {Overridepublic void run() {synchronized (lock) {while (foodCount MAX_FOOD) {try {// 厨师准备菜肴System.out.println(厨师准备菜肴...);Thread.sleep(1000);// 菜肴准备好后唤醒服务员foodCount;lock.notify();} catch (InterruptedException e) {e.printStackTrace();}}}}}static class Waiter extends Thread {Overridepublic void run() {synchronized (lock) {while (foodCount MAX_FOOD) {try {// 等待菜肴准备好lock.wait();// 将菜肴送到顾客那里System.out.println(服务员将菜肴送到顾客那里...);Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}}}}}static class Customer extends Thread {Overridepublic void run() {synchronized (lock) {while (foodCount MAX_FOOD) {try {// 等待菜肴送来lock.wait();// 开始吃菜肴System.out.println(顾客开始吃菜肴...);Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}}}}} } 运行结果 就是厨师准备好菜肴之后main线程结束 所以才会选择子线程的方式有大佬知道为啥会出现这样的结果吗评论区聊聊
http://wiki.neutronadmin.com/news/33313/

相关文章:

  • 自己做电影网站可以赚钱吗企业邮箱的个人邮箱
  • 湖南建设长沙网站建设价格建筑做文本网站
  • 网站设计模板百度云公司网站免费网站免费
  • 搜索排名广告营销怎么做wordpress手动数据库优化
  • 公司网址怎么做出来的和平网站建设优化seo
  • 互站网怎么样做本地地旅游网站
  • 西数 网站建设建网站用什么语言
  • 仿网站 涉及侵权吗python写网页
  • 个人网站如何制作高清视频服务器内存
  • 2018年网站开发语言排行shopify
  • 网站建设实训心得体会300字营销型网站建设教程
  • 求个网站好人一生平安非常赚又一个wordpress站点
  • 公司网站制作范文厦门外贸网站建
  • 网站建设中标通州网站制作
  • 产品设计网站官网网站开发全科班
  • 网站导航页面设计湖北 商城网站建设多少钱
  • 织梦网站栏目无法生成怎么在手机上做微电影网站
  • 网站黑链检测端午节网站怎么做
  • 网站设计的关键做的比较好看的国内网站
  • 站长统计免费下载网络推广公司重诚
  • 邢台大峡谷烟台seo网站诊断
  • 陕西网站建设价格佛山顺德容桂网站制作
  • 对网站开发的理解500字wordpress 简洁主题
  • 查看网站域名网站搜索引擎提交
  • 网站平台如何推广济南中建设计院 官方网站
  • 潍坊市建设工程质量安全监督站网站wordpress主题的文件在哪个文件夹
  • 平乡县网站建设国内服装电商平台
  • 大型网站制作平台苏州保洁公司哪家最好
  • 进口食品销售销售在那个网站做个人网站建设的目的
  • 网站建设行业网站wordpress类别id