一、sleep和wait的区别。

1.wait可以指定时间,也可以不指定。

而sleep必须制定。

2.在同步的时候,对于CPU的执行权和以及锁的处理不同。

wait:释放执行权,释放锁。

sleep:释放执行权,不释放锁。

二、线程是否安全?

 1 class Test implements Runnable
 2 {
 3     public synchronized void show()
 4     {
 5         try
 6         {
 7             wait();
 8         }
 9         catch (InterruptedException e)
10         {
11         }
12     }
13     public synchronized void method()
14     {
15         notifyAll();
16     }
17 }
View Code

相关文章:

  • 2021-06-07
  • 2022-12-23
  • 2021-06-19
  • 2021-10-16
  • 2021-12-13
  • 2021-07-04
猜你喜欢
  • 2021-12-24
  • 2021-12-30
  • 2021-09-07
  • 2021-11-17
  • 2021-12-13
  • 2021-12-07
相关资源
相似解决方案