Skip to content

Commit

Permalink
doc: 修改图片外链
Browse files Browse the repository at this point in the history
  • Loading branch information
01Petard committed Nov 7, 2024
1 parent 685cdac commit a78db36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default {
{text: 'SSO单点登录的实现原理', link: '/开发/SSO单点登录的实现原理'},
{text: '批量导出zip压缩包和Excel表格', link: '/开发/批量导出zip压缩包和Excel表格'},
{text: '阿里云OSS && 内容安全 Java实现参考代码', link: '/开发/阿里云OSS && 内容安全 Java实现参考代码'},
{text: '抖音评论区设计', link: '/开发/抖音评论区设计'},
{
text: 'My Java Guide',
collapsed: false,
Expand Down
28 changes: 14 additions & 14 deletions docs/开发/My Java Guide/My Java Guide - Java基础.md
Original file line number Diff line number Diff line change
Expand Up @@ -1868,24 +1868,24 @@ ReentrantLock相对于synchronized它具备以下特点:

## synchronizedLock 有什么区别 ?

| 特点 | synchronized | Lock |
| :----------: | ------------------------------------------------------------ | ------------------------------------------------------------ |
| 特点 | synchronized | Lock |
| :----------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| **语法层面** | 关键字,源码在 JVM 中,用 C++ 实现<br />使用时,退出同步代码块锁会自动释放 | 接口,源码由 JDK 提供,用 Java 语言实现<br />使用时,需要手动调用 `unlock` 方法释放锁 |
| **功能层面** | 悲观锁,具备互斥、同步、锁重入功能 | 悲观锁,具备互斥、同步、锁重入功能<br />提供了更多功能,如获取等待状态、公平锁、可打断、可超时、多条件`Condition`变量<br />有适合不同场景的实现,如 `ReentrantLock`,`ReentrantReadWriteLock` |
| **性能层面** | 在没有竞争时,做了很多优化,如偏向锁、轻量级锁 | 在竞争激烈时,通常会提供更好的性能 |
| **功能层面** | 悲观锁,具备互斥、同步、锁重入功能 | 悲观锁,具备互斥、同步、锁重入功能<br />提供了更多功能,如获取等待状态、公平锁、可打断、可超时、多条件`Condition`变量<br />有适合不同场景的实现,如 `ReentrantLock`,`ReentrantReadWriteLock` |
| **性能层面** | 在没有竞争时,做了很多优化,如偏向锁、轻量级锁 | 在竞争激烈时,通常会提供更好的性能 |

## synchronizedReentrantLock 有什么区别 ?

| 特性 | synchronized | ReentrantLock |
| ------------------------ | -------------------------------- | ------------------------------------------- |
| **类别** | Java关键字 | Java中的一个类 |
| **锁类型** | JVM层面的锁 | Java API层面的锁 |
| **加锁/解锁方式** | 自动加锁与释放锁 | 需要手动加锁与释放锁 |
| **获取当前线程是否上锁** | 不可获取 | 可获取 (`isHeldByCurrentThread()`) |
| **公平性** | 默认非公平锁 | 公平锁或非公平锁 |
| **中断支持** | 不可中断 | 可中断 (`tryLock()`, `lockInterruptibly()`) |
| **锁的对象** | 锁的是对象,锁信息保存在对象头中 | int类型的state标识来标识锁的状态 |
| **锁升级** | 底层有锁升级过程 | 没有锁升级过程 |
| 特性 | synchronized | ReentrantLock |
| :----------------------: | :------------------------------: | :-----------------------------------------: |
| **类别** | Java关键字 | Java中的一个类 |
| **锁类型** | JVM层面的锁 | Java API层面的锁 |
| **加锁/解锁方式** | 自动加锁与释放锁 | 需要手动加锁与释放锁 |
| **获取当前线程是否上锁** | 不可获取 | 可获取 (`isHeldByCurrentThread()`) |
| **公平性** | 默认非公平锁 | 公平锁或非公平锁 |
| **中断支持** | 不可中断 | 可中断 (`tryLock()`, `lockInterruptibly()`) |
| **锁的对象** | 锁的是对象,锁信息保存在对象头中 | int类型的state标识来标识锁的状态 |
| **锁升级** | 底层有锁升级过程 | 没有锁升级过程 |

<img src="https://cdn.jsdelivr.net/gh/01Petard/imageURL@main/img/202411071516196.png" alt="img" style="zoom: 80%;" />

Expand Down

0 comments on commit a78db36

Please sign in to comment.