生产电脑|学习笔记

简介: 快速学习 生产电脑

开发者学堂课程【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();

相关文章
|
Docker 容器
解决:Error response from daemon: manifest for xxx:latest not found: manifest unknown.
解决:Error response from daemon: manifest for xxx:latest not found: manifest unknown.
1747 0
|
数据采集 数据管理 大数据
推荐 | AllData开源数据中台技术分享
AllData数据中台架构师团队全面解析开源项目[alldata](https://github.com/alldatacenter/alldata),涵盖功能设计、架构分析及源码解读。团队分享了项目总结、发展规划,推荐关注公众号“大数据商业驱动引擎”以获取更多信息。他们讨论了数据治理、调度引擎、商业化探索及未来规划,涉及元数据管理、数据安全、Airflow调度引擎等。此外,还介绍了数据平台功能,如用户管理、权限控制,并提到了商业化版本的源码支持。鼓励用户参与社区交流,共同推动项目发展。
推荐 | AllData开源数据中台技术分享
|
存储 弹性计算 运维
|
4天前
|
云安全 人工智能 自然语言处理
|
8天前
|
人工智能 Java API
Java 正式进入 Agentic AI 时代:Spring AI Alibaba 1.1 发布背后的技术演进
Spring AI Alibaba 1.1 正式发布,提供极简方式构建企业级AI智能体。基于ReactAgent核心,支持多智能体协作、上下文工程与生产级管控,助力开发者快速打造可靠、可扩展的智能应用。
803 17
|
11天前
|
数据采集 人工智能 自然语言处理
Meta SAM3开源:让图像分割,听懂你的话
Meta发布并开源SAM 3,首个支持文本或视觉提示的统一图像视频分割模型,可精准分割“红色条纹伞”等开放词汇概念,覆盖400万独特概念,性能达人类水平75%–80%,推动视觉分割新突破。
805 59
Meta SAM3开源:让图像分割,听懂你的话
|
2天前
|
人工智能 安全 小程序
阿里云无影云电脑是什么?最新收费价格个人版、企业版和商业版无影云电脑收费价格
阿里云无影云电脑是运行在云端的虚拟电脑,分企业版和个人版。企业版适用于办公、设计等场景,4核8G配置低至199元/年;个人版适合游戏、娱乐,黄金款14元/月起。支持多端接入,灵活按需使用。
239 164