Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 12 by
martin.v...@gmail.com: Test clasims the thread will not
finish but they should
https://code.google.com/p/thread-weaver/issues/detail?id=12
What steps will reproduce the problem?
1. create an object with the followings method and field
private ConcurrentMap<Object, CountDownLatch> latchesPerKeys = new
ConcurrentHashMap<Object, CountDownLatch>();
public void testedMethod(Map<K, V> values, Object key) {
CountDownLatch newLatch = new CountDownLatch(1);
CountDownLatch oldLatch = latchesPerKeys.putIfAbsent(key, newLatch);
if (oldLatch == null) { // the first thread
newLatch.countDown();
}
else { // the second thread
try {
boolean succWait = oldLatch.await(5, TimeUnit.SECONDS);
if (!succWait) {
oldLatch.countDown();
}
}
catch (InterruptedException e) {
}
}
}
2. test it with
@ThreadedMain
public void mainThread() {
Map<Integer, Integer> values = new HashMap<Integer, Integer>();
object.testedMethod(values, 1);
}
@ThreadedSecondary
public void secondThread() {
Map<Integer, Integer> values = new HashMap<Integer, Integer>();
object.testedMethod(values, 1);
}
3.
What is the expected output? What do you see instead?
Test should be green but it says that "Thread will not finish".
What version of the product are you using? On what operating system?
ThreadWeaver 0.2 on Windows 7.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings