Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:fix UUID generate blocked #507

Merged
merged 3 commits into from
Jun 13, 2023
Merged

fix:fix UUID generate blocked #507

merged 3 commits into from
Jun 13, 2023

Conversation

ZPZP1
Copy link
Contributor

@ZPZP1 ZPZP1 commented Jun 7, 2023

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style
  • Refactor
  • Doc
  • Other, please describe:

The description of the PR:
UUID在jdk版本小于JDK8u112时存在高并发阻塞bug,详情参考:https://heapdump.cn/article/4421829 ,因此采用优化雪花算法的id生成器IdGenerator来生成事务id。
Other information:
问题来源: #504

@ZPZP1
Copy link
Contributor Author

ZPZP1 commented Jun 7, 2023

JDK8u112前高并发下生成UUID当操作系统中缺少“熵”时,随机数的生成将减慢。当速度变慢时,调用此“java.util.UUID#randomUUID()”API 调用的应用程序线程将被置于 BLOCKED 状态,它们将无法继续前进。

@huayanYu
Copy link
Member

不太想引入第三方库

@ZPZP1
Copy link
Contributor Author

ZPZP1 commented Jun 12, 2023

嗯嗯,我试试用线程私有的SecureRandom对象可不可以解决这个问题。

@ZPZP1
Copy link
Contributor Author

ZPZP1 commented Jun 12, 2023

已修改为使用线程私有的SecureRandom对象来生成随机数,从而避免高并发下生成种子时的锁竞争。
锁竞争

@huayanYu huayanYu merged commit 34a9ae7 into baomidou:master Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants