自2006年以来 我撰写了profiler,重点是concurrency方面,我正在利用synchronization mechanisms在的
- calling notify/wait
- thread changes its state
- a thread is contended with another thread for a monitor lock
- a monitor lock has been acquired by a thread after contending for it with another
- measure the execution time of each method
- which thread has accessed a certain method and how often
- etc.
因此,我所期待的是“ Java”方案,该方案似乎在第一期上得到理解,但在执行该方案时,你开始怀疑结果。 我希望,我的简介员可能能够发现正在经历的情况。
澄清自己 我举例说,Brian Goetz著《Java Concurrency in Practice》提供了“毒性”编码实例,用于学习。
@NotThreadSafe
public class ListHelper<E> {
public List<E> list =
Collections.synchronizedList(new ArrayList<E>());
...
public synchronized boolean putIfAbsent(E x) {
boolean absent = !list.contains(x);
if (absent)
list.add(x);
return absent;
}
}
目的是通过putIfAbsent
则使用另一锁保护国家,作为清单中界定的方法。
The profiler could display the used monitor locks and to the suprise of the user (or not...) the user would see there are two possible monitor locks instead of one.
我不像这个例子那么多,但我要提的是,我是否已经有了一些好的例子。
我发现我的问题与此类似:。 Java中遇到的最常见的一致问题是什么?和。
But they refer only to broken concurrent programs. I am also looking for thread-safe implementations, but where it still not obvious that they are thread-safe.