生产电脑|学习笔记

简介: 快速学习 生产电脑

开发者学堂课程【Java 高级编程生产电脑 】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/20/detail/300


生产电脑


多线程案例分析二

 

题目:设计一个生产电脑和搬运电脑类,要求生产出一台电脑就搬走一台电脑,如果没有新的电脑生产出来,则搬运工要等待新电脑产出,如果生产出的电脑没有搬走,则要等待电脑搬走之后再生产,并统计出生产的电脑数量。

 

在本程序之中实现的就是一个标准的生产者与消费者的处理模型,实现操作的代码如下:

package cn.mldn.demo;

class Producer implements Runnable {

private Resource resource;

public Producer (Resource resource) {

this.resource = resource ;

public void run(){

class Resource{

private Computer computer ;

public synchronized void make() throws Exception{if (this.computer !=null){//已经生产过了

super.wait();

this.computer=newComputer("MLDN牌电脑,",1.1);

super.notifyAll();

public synchronized void get() throws Exception {

if (this.computer == null)  {//没有生产过

super.wait();

System.out.println(this. computer);

private Resource resource ;

public Consumer ( Resource resource)  {

this.resource = resource ;

public voidrun() {

for(int x = 0 ;x< 50;x++)  {

try  {

this.resource.get();

catch (Exception e)  {

e.printStackTrace( );

class Resource

private Computer computer ;

publicsynchronized void make() throws Exception {if (this. computer != null) {//已经生产过了

super.wait( );

Thread.sleep(100);

this.computer=newComputer("MLDN牌电脑",1.1) ;

System.out.print1n("生产" + this. computer);

super.notifyAll();

public synchronized void get() throws Exception {

if (this. computer == null) (//没有生产过

super .wait();

Thread.sleep(10);

System.out.println("生产电脑" + this. computer);this. computer = null ; //已经取走了super.notifyAll();

相关文章
|
存储 弹性计算 运维
|
2天前
|
数据采集 人工智能 安全
|
11天前
|
云安全 监控 安全
|
3天前
|
自然语言处理 API
万相 Wan2.6 全新升级发布!人人都能当导演的时代来了
通义万相2.6全新升级,支持文生图、图生视频、文生视频,打造电影级创作体验。智能分镜、角色扮演、音画同步,让创意一键成片,大众也能轻松制作高质量短视频。
1017 151
|
3天前
|
编解码 人工智能 机器人
通义万相2.6,模型使用指南
智能分镜 | 多镜头叙事 | 支持15秒视频生成 | 高品质声音生成 | 多人稳定对话
|
16天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
1711 9
|
8天前
|
人工智能 自然语言处理 API
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸
一句话生成拓扑图!next-ai-draw-io 结合 AI 与 Draw.io,通过自然语言秒出架构图,支持私有部署、免费大模型接口,彻底解放生产力,绘图效率直接爆炸。
652 152
|
10天前
|
人工智能 安全 前端开发
AgentScope Java v1.0 发布,让 Java 开发者轻松构建企业级 Agentic 应用
AgentScope 重磅发布 Java 版本,拥抱企业开发主流技术栈。
620 12