Java 中锁的大量条件是否存在潜在问题?

发布于 2024-09-18 16:17:26 字数 199 浏览 2 评论 0原文

首先是一些背景知识:在 Java 中,所有条件等待的构造都允许虚假唤醒,这可能会扰乱公平性。我一直在尝试编写一个读写锁的实现,该锁按严格的到达顺序为传入线程提供服务。

现在,每次线程进入我编写的类时,我的算法都会创建一个新的 java.util.concurrent.Condition。我想知道这种行为是否可取,或者这种模式是否会产生一些不良的副作用,例如大幅放缓。

First some background: In Java all the constructs for conditional waiting allows for spurious wakeups which can mess with fairness. I've been toying with writing an implementation for a ReadWrite lock which serves the incoming threads in strict order-of-arrival.

Now, my algorithm creates a new java.util.concurrent.Condition each time a thread enters the class I've written. I wonder whether this kind of behavior is advisable or if there are some bad side effects of this kind of patterns, like massive slowdown.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2024-09-25 16:17:26

好吧,就像所有性能问题一样,您通常应该首先尝试干净的方式,然后再进行测试。话虽这么说,创建和 GC 短期对象(甚至是很多对象)是 JVM 特别擅长的。

Well, like all performance issues you should generally try it the clean way first and then test. That being said creating and GCing short lived objects – even a lot of them – is what JVMs are particularly good at.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文