老师 我想请问一下 我想让我选择的英雄打印出来 应该怎么做
老师,为啥有的时候新建节点,用的是Node,为啥有的时候就要Node<E>,呢
老师我的fake-useragent用不了是因为没有在虚拟环境中安装吗,我的代码现在在虚拟环境里,但下面自动出来的文件路径还是python,没有精确到虚拟环境,要怎么调整啊
老师 你是咋把图片搞进来的
老师 我这咋回事 我往里面加了东西 加了 然后再读 就不行
老师 这儿为什么有两个lines 代表什么
具体服务器编程在哪个章节的哪个部分
这里的this指向全局环境不太明白诶 为什么执行user外的name
点运行之后,页面还是QWE,怎么回事?刷新也没用
为什么我输入完,一直是qwe,点刷新也没有出现asd啊
视频是什么时候更新的?感觉不是最新的?
老师 我这咋回事
http是请求和响应,怎么还可以提交文件吗?
为什么这里不需要返回值
package com.Thread; //生产者和消费者模式 public class produceThreadTest { public static void main(String[] args) { //创建缓冲区 SyncStack ss = new SyncStack(); //启动生产者线程 produce producer = new produce(ss); new Thread(producer).start(); //启动消费者线程 new customer(ss).start(); } } //定义馒头类代表数据 class Mantou{ private int id; public int getId() { return id; } public void setId(int id) { this.id = id; } } //定义缓冲区 class SyncStack { //用数组表示放馒头的盒子 private Mantou[] mantous = new Mantou[10]; //定义索引用来操作盒子 private int index; //定义放馒头的方法 public synchronized void SetMantou(Mantou mantou) { //当馒头放满时,线程进行等待 while (this.index == this.mantous.length) { try { /** * wait()是Object类下的方法; * wait()语法:该方法需要在synchronized语句块中使用; * wait()执行后,线程会将持有的对象锁释放,并进入阻塞状态、使其他持有该对象锁的线程可以继续运行 */ this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } this.notify(); this.mantous[this.index] = mantou; this.index++; } //定义取馒头的方法 public synchronized Mantou GetMantou() { while (this.index == 0) { try { this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } //唤醒等待中的其中一个线程、需使用在synchronized语句块中 this.notify(); this.index--; return this.mantous[this.index]; } } //定义生产者线程类 class produce implements Runnable{ private SyncStack syncStack; public produce(SyncStack syncStack) { this.syncStack = syncStack; } public void run() { for(int i = 0;i < 10;i++){ Mantou mantou = new Mantou(); mantou.setId(i); this.syncStack.SetMantou(mantou); System.out.println("生成馒头 "+mantou.getId()); } } } //定义消费者线程类 class customer extends Thread{ private SyncStack syncStack; public customer(SyncStack syncStack) { this.syncStack = syncStack; } public void run() { for (int i = 0;i<10;i++){ Mantou mantou = this.syncStack.GetMantou(); System.out.println("取馒头 "+mantou.getId()); } } }
疑问:为什么我运行后,会先取馒头再生产馒头?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637