notifyall怎么在java中使用

  介绍

今天就跟大家聊聊有关notifyall怎么在java中使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

java可以用来干什么

java主要应用于:1。网页开发;2。Android开发;3。客户端开发;4。网页开发;5。企业级应用开发;6。Java大数据开发;7。游戏开发等。

<强> 1。概念

对象调用该方法时,队列中所有处于阻塞状态的线程不再阻塞(当然,哪一个线程先运行由系统决定)

<强> 2。语法

 public  final  void  notifyAll () 

<强> 3。参数

<强> 4。返回值

没有返回值

<强> 5。使用注意

唤醒的是通知之前等待的线程,对于通知之后的等待线程是没有效果的。

<强> 6。实例

 class  myThread  implements  Runnable {
  ,,,private  boolean  flag ;
  ,,,private  Object  Object ;
  ,
  ,,,myThread (boolean ,国旗,Object  o) {
  ,,,,,,,this.flag =,国旗;
  ,,,,,,,this.object =, o;
  ,,,}
  ,,,private  void  waitThread () {
  ,,,,,,,synchronized (对象),{
  ,,,,,,,,,,,System.out.println (Thread.currentThread () . getname (), +,“wait 开始…“);
  ,,,,,,,,,,,try  {
  ,,,,,,,,,,,,,,,object.wait ();
  ,,,,,,,,,,,},catch  (InterruptedException  e), {
  ,,,,,,,,,,,,,,,e.printStackTrace ();
  ,,,,,,,,,,,}
  ,,,,,,,,,,,System.out.println (Thread.currentThread () . getname (), +,“wait 结束…“);
  ,,,,,,,}
  ,,,}
  ,,,private  void  notifyThread () {
  ,,,,,,,synchronized (对象),{
  ,,,,,,,,,,,System.out.println (Thread.currentThread () . getname (), +,“notify 开始…“);
  ,,,,,,,,,,,object.notify ();
  ,,,,,,,,,,,System.out.println (Thread.currentThread () . getname (), +,“notify 结束…“);
  ,,,,,,,}
  ,,,}
  ,,@Override
  ,,,public  void 运行(),{
  ,,,,,,,如果(国旗){
  ,,,,,,,,,,,waitThread ();
  ,,,,,,,}else  {
  ,,,,,,,,,,,notifyThread ();
  ,,,,,,,}
  ,,,}
  }
  public  class  Test  {
  ,,,public  static  void  main (String [], args), throws  InterruptedException  {
  ,,,,,,,Object  Object =, new 对象();
  ,,,,,,,myThread  mt2 =, new  myThread (false,对象);
  ,,,,,,,Thread  thread1 =, new 线程(是,“线程B “);
  ,,,,,,,for  (int 小姐:=,0;i<10;我+ +),{
  ,,,,,,,,,,,myThread  mt =, new  myThread(真的,对象);
  ,,,,,,,,,,,Thread  Thread =, new 线程(太,“线程A “+ i);
  ,,,,,,,,,,,thread.start ();
  ,,,,,,,}
  ,,,,,,,thread . sleep (1000);
  ,,,,,,,thread1.start ();
  ,,,}
  }

看完上述内容,你们对notifyall怎么在java中使用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。

notifyall怎么在java中使用