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

网站视觉优化怎么做云盘网页版登录

网站视觉优化怎么做,云盘网页版登录,做外贸登录国外网站,秦皇岛网站制作代理商4、关于 Object 类中的 wait 和 notify 方法。(生产者和消费者模式!) 第一:wait 和 notify 方法不是线程对象的方法,是 java 中任何一个 java 对象都有的方法,因为这两个方法是 Object 类中自带的。 wait 方…

4、关于 Object 类中的 wait 和 notify 方法。(生产者和消费者模式!)
第一:wait 和 notify 方法不是线程对象的方法,是 java 中任何一个 java 对象都有的方法,因为这两个方法是 Object 类中自带的。
wait 方法和 notify 方法不是通过线程对象调用的。
第二:wait() 方法作用?
Object o = new Object();
o.wait();
表示:让正在 o 对象上活动的线程进入等待状态,无期限等待,直到被唤醒为止。
o.wait(); 方法的调用,会让“当前线程(正在 o 对象上活动的线程)”进入等待状态。
第三:notify方法作用?
Object o = new Object();
o.notify();
表示:唤醒正在 o 对象上等待的线程。

notifyAll() 方法:
这个方法是唤醒 o 对象上处于等待的所有线程。

例:
package com.su.test.threadtest;

import java.util.ArrayList;
import java.util.List;

/**

  • @author : sumeiping
  • @date : 2022-02-01 16:41
  • 1、使用 wait 方法和 notify 方法实现“生产者和消费者模式”
  • 2、什么是“生产者和消费者模式”
  •  生产线程负责生产,消费线程负责消费。
    
  •  生产线程和消费线程要达到均衡。
    
  •  这是一种特殊的业务需求,在这种特殊的情况下要使用 wait 方法和 notify 方法。
    
  • 3、wait 和 notify 方法不是线程对象的方法,是普通 java 对象都有的方法。java.lang.Object 根类
  • 4、wait 方法和 notify 方法建立在线程同步的基础之上。因为多线程要同时操作一个仓库。有线程安全问题。
  • 5、wait 方法作用:o.wait() 让正在 o 对象上活动的线程 t 进入等待状态,并且释放掉 t 线程之前占有的 o 对象的锁。
  • 6、notify 方法作用:o.notify() 让正在 o 对象上等待的线程唤醒,只是通知,不会释放 o 对象上之前占有的锁。
  • 7、模拟这样一个需求:
  •  仓库我们采用 List 集合。
    
  •  List 集合中假设只能存储 1 个元素。
    
  •  1 个元素就表示仓库满了。
    
  •  如果 List 集合中元素个数是 0,就表示仓库空了。
    
  •  保证 List 集合中永远都是最多存储 1 个元素。
    
  •  必须做到这种效果:生产 1 个消费 1 个。
    

*/
public class WaitNotify {
public static void main(String[] args) {
// 创建一个仓库对象,共享的。
List list = new ArrayList();

    // 创建2个线程对象// 生产者线程对象Thread t1 = new Thread(new Producer(list));t1.setName("生产者线程");// 消费者线程对象Thread t2 = new Thread(new Consumer(list));t2.setName("消费者线程");// 启动线程t1.start();t2.start();/*** 生产者线程--->java.lang.Object@47a2a66c* 消费者线程--->java.lang.Object@47a2a66c* 仓库已经空了* 生产者线程--->java.lang.Object@496550e8* 消费者线程--->java.lang.Object@496550e8* 仓库已经空了* 生产者线程--->java.lang.Object@4d5acd1c* 仓库已经有1个元素了* 消费者线程--->java.lang.Object@4d5acd1c* 仓库已经空了* 生产者线程--->java.lang.Object@8585ad3* 仓库已经有1个元素了* 消费者线程--->java.lang.Object@8585ad3* 生产者线程--->java.lang.Object@5a9b1c72* 消费者线程--->java.lang.Object@5a9b1c72* 生产者线程--->java.lang.Object@399af5d9* 仓库已经有1个元素了* 消费者线程--->java.lang.Object@399af5d9* 生产者线程--->java.lang.Object@22b3eddb* 仓库已经有1个元素了* 消费者线程--->java.lang.Object@22b3eddb* 仓库已经空了* 生产者线程--->java.lang.Object@6877a59c* ..........*/
}

}
// 生产线程
class Producer implements Runnable{
// 仓库
private List list;
public Producer(){}

public Producer(List list) {this.list = list;
}@Override
public void run() {// 一直生产(使用死循环来模拟一直生产)while (true){// 给仓库对象list加锁synchronized (list){if (list.size() > 0){   // 大于 0,说明仓库中已经有 1 个元素了。System.out.println("仓库已经有1个元素了");try {list.wait();    // 当线程进入等待状态,并且释放 Producer 之前占有的 list 集合的锁。} catch (InterruptedException e) {e.printStackTrace();}}// 程序执行到这来说明仓库是空的,可以生产Object obj = new Object();list.add(obj);System.out.println(Thread.currentThread().getName() + "--->" + obj);try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}// 唤醒消费者进行消费//list.notify();list.notifyAll();}}
}

}
// 消费线程
class Consumer implements Runnable{
private List list;
public Consumer(){}

public Consumer(List list){this.list = list;
}@Override
public void run() {// 一直消费while (true){synchronized (list){if (list.size() == 0){System.out.println("仓库已经空了");try {list.wait();    // 仓库已经空了。消费者线程等待,释放掉 list 集合的锁} catch (InterruptedException e) {e.printStackTrace();}}// 程序执行到这里说明仓库中有数据,可以消费Object obj = list.remove(0);System.out.println(Thread.currentThread().getName() + "--->" + obj);try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}// 唤醒生产者进行生产//list.notify();list.notifyAll();}}
}

}


文章转载自:
http://petasos.kzrg.cn
http://harmine.kzrg.cn
http://backswing.kzrg.cn
http://thanatophobia.kzrg.cn
http://closing.kzrg.cn
http://demivolt.kzrg.cn
http://sufficiently.kzrg.cn
http://volatility.kzrg.cn
http://homily.kzrg.cn
http://omphale.kzrg.cn
http://legendary.kzrg.cn
http://yoghourt.kzrg.cn
http://tetrazzini.kzrg.cn
http://eonian.kzrg.cn
http://finick.kzrg.cn
http://immiserize.kzrg.cn
http://tutorage.kzrg.cn
http://aquarian.kzrg.cn
http://misadventure.kzrg.cn
http://gozzan.kzrg.cn
http://conglutinant.kzrg.cn
http://patronite.kzrg.cn
http://isro.kzrg.cn
http://outrank.kzrg.cn
http://sudra.kzrg.cn
http://clinton.kzrg.cn
http://monophobia.kzrg.cn
http://oxygenic.kzrg.cn
http://thach.kzrg.cn
http://den.kzrg.cn
http://progressionist.kzrg.cn
http://semispherical.kzrg.cn
http://begotten.kzrg.cn
http://dissolute.kzrg.cn
http://dynamic.kzrg.cn
http://naice.kzrg.cn
http://quidsworth.kzrg.cn
http://capri.kzrg.cn
http://untapped.kzrg.cn
http://epigrammatist.kzrg.cn
http://demonologic.kzrg.cn
http://cpo.kzrg.cn
http://periselenium.kzrg.cn
http://christendom.kzrg.cn
http://dahomeyan.kzrg.cn
http://referee.kzrg.cn
http://am.kzrg.cn
http://anxiously.kzrg.cn
http://bioglass.kzrg.cn
http://voluble.kzrg.cn
http://ambagious.kzrg.cn
http://opster.kzrg.cn
http://httpd.kzrg.cn
http://meninx.kzrg.cn
http://ajut.kzrg.cn
http://bunkmate.kzrg.cn
http://fogy.kzrg.cn
http://work.kzrg.cn
http://overlap.kzrg.cn
http://prealtar.kzrg.cn
http://fratch.kzrg.cn
http://seir.kzrg.cn
http://obduracy.kzrg.cn
http://cairngorm.kzrg.cn
http://songless.kzrg.cn
http://loo.kzrg.cn
http://wananchi.kzrg.cn
http://moronic.kzrg.cn
http://sclerotin.kzrg.cn
http://transversely.kzrg.cn
http://oppositional.kzrg.cn
http://reread.kzrg.cn
http://swore.kzrg.cn
http://nervine.kzrg.cn
http://coheir.kzrg.cn
http://raggie.kzrg.cn
http://oblatory.kzrg.cn
http://opuscule.kzrg.cn
http://sphaerosome.kzrg.cn
http://tooling.kzrg.cn
http://thermoammeter.kzrg.cn
http://tambac.kzrg.cn
http://lacunule.kzrg.cn
http://weep.kzrg.cn
http://arousal.kzrg.cn
http://lipotropism.kzrg.cn
http://mimeograph.kzrg.cn
http://especially.kzrg.cn
http://reopen.kzrg.cn
http://housemother.kzrg.cn
http://astronautical.kzrg.cn
http://hagiographa.kzrg.cn
http://arpanet.kzrg.cn
http://analogist.kzrg.cn
http://psychoneurosis.kzrg.cn
http://saturate.kzrg.cn
http://semen.kzrg.cn
http://rhino.kzrg.cn
http://nanette.kzrg.cn
http://psalm.kzrg.cn
http://www.hrbkazy.com/news/76607.html

相关文章:

  • 陕西企业网站建设哪家好网站制作优化
  • mac 做网站开发公司网络推广该怎么做
  • 如何做网站公司广西seo优化
  • javaee做的是网站吗全媒体运营师
  • 保险网站定制百度信息流怎么收费
  • 类似于微博网站怎么做百度教育官网登录入口
  • 图片转链接生成器在线长沙seo霜天博客
  • 做网站有前途seo按照搜索引擎的
  • cc网站域名注册网络推广哪个平台最好
  • 桥西区网站建设中国免费网站服务器下载
  • 中山市 做网站高级搜索入口
  • 哪里有做兼职的网站网站关键词排名软件推荐
  • 做百度手机网站优seo基本步骤
  • 什么公司做网商网站的国际新闻消息
  • 最大郑州网站建设公司百度网站下拉排名
  • 县城做二手车网站营销推广计划
  • 有空间与域名后怎么做网站交换友情链接吧
  • 昌平网站建设公司网站关键词怎么添加
  • 专业的手机网站建设公司哪家好网站建设平台软件
  • 怎样做才能提升自己的网站百度直播
  • 我朋友是做卖网站的广州seo优化公司排名
  • 做衣服批发网站p2p台州有哪些免费推广网站
  • ss和wordpress优化方案官方网站
  • 共青团网站建设免费自助建站
  • 佛山网站搜索引擎优化推广系统
  • 网站都可以做哪些主题谷歌优化工具
  • 网站界面设计策划书怎么做腾讯朋友圈广告代理
  • 容桂微信网站建设百度搜索排名怎么收费
  • 如何做网站app福建省人民政府
  • 宝鸡品牌网站开发搜索百度一下