为什么等待,通知和notifyAll方法都在Object Class中? [英] Why wait ,notify and notifyAll Methods are in Object Class?

查看:112
本文介绍了为什么等待,通知和notifyAll方法都在Object Class中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道wait()方法总是用synchronized方法/块编写并对Object进行锁定但是我想知道当所有方法都在Thread类中时出现了什么问题?

i know that wait() method always written in synchronized method/block and make lock on Object but i want to only know that what problem is arise at that time when this all methods are in Thread class ?

推荐答案

在Thread对象上使用它们的问题是Thread为了它自己的目的而使用这个锁。这可能会导致混乱和奇怪的错误。

The problem with using them on a Thread object is that the Thread uses this lock for it own purposes. This is likely to lead to confusion and odd bugs.

这篇关于为什么等待,通知和notifyAll方法都在Object Class中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆