Java 中锁的大量条件是否存在潜在问题?
首先是一些背景知识:在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,就像所有性能问题一样,您通常应该首先尝试干净的方式,然后再进行测试。话虽这么说,创建和 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.