Java多线程系列(三)JAVA Object对象 多线程概念分析

本文深入分析了Java中Object对象的Monitor机制,揭示了其内部的等待集(waitset)概念,以及线程如何拥有对象的Monitor,为理解Java并发提供了关键洞见。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在不查看JVM源码的情况下,通过JAVA层的注释分析Object对象

有如下注释:

Wakes up a single thread that is waiting on this object's
* monitor   (notify方法)
The current thread must own this object's monitor.(wait方法)

源码中这种“object's monitor”比比皆是

由此,可以的出第一个结论:

1. object有一个monitor

继续分析

This method causes the current thread (call it <var>T</var>) to
* place itself in the wait set for this object and then to relinquish
The thread <var>T</var> is then removed from the wait set for this
* object and re-enabled for thread scheduling.

由此可以得到第二个结论

2. object有一个wait set

 

继续分析

The current thread must own this object's monitor
Only one thread at a time can own an object's monitor.

由此我们可以得到结论

3. thread可以own object's monitor

......

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值