提交 95976ee1 编写于 作者: D dcubed

4926961: 4/4 TransformerManagementThreadRemoveTests hangs

Summary: Changes motivated by Effective Java - Item 48 & Item 51.
Reviewed-by: sspitsyn
上级 a66a3f5b
......@@ -137,9 +137,16 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
threads[i].start();
}
while (!exec.fDone)
// Effective Java - Item 48: Synchronize access to shared mutable data
// Don't use a direct field getter.
while (!exec.isDone())
{
Thread.currentThread().yield();
// Effective Java - Item 51: Don't depend on the thread scheduler
// Use sleep() instead of yield().
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
}
}
assertTrue(finalCheck());
......@@ -175,13 +182,17 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
this.fExec = exec;
}
// Effective Java - Item 48: Synchronize access to shared mutable data
// Document a synchronized setter.
protected synchronized void
threadFinished(Thread t)
{
fFinished++;
}
protected boolean
// Effective Java - Item 48: Synchronize access to shared mutable data
// Provide synchronized getter.
protected synchronized boolean
threadsDone()
{
return fFinished == TOTAL_THREADS;
......@@ -194,7 +205,9 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
protected boolean
testCompleted()
{
return getExecThread().fDone;
// Effective Java - Item 48: Synchronize access to shared mutable data
// Don't use direct field getter.
return getExecThread().isDone();
}
/**
......@@ -339,6 +352,18 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
{
private boolean fDone = false;
// Effective Java - Item 48: Synchronize access to shared mutable data
// Provide a synchronized getter.
private synchronized boolean isDone() {
return fDone;
}
// Effective Java - Item 48: Synchronize access to shared mutable data
// Provide a synchronized setter.
private synchronized void setIsDone() {
fDone = true;
}
public void
run()
{
......@@ -349,7 +374,9 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
// Do a final check for good measure
executeTransform();
fDone = true;
// Effective Java - Item 48: Synchronize access to shared mutable data
// Don't use direct field setter.
setIsDone();
}
}
......
......@@ -27,10 +27,9 @@
* @summary multi-thread test to exercise sync and contention for removes to transformer registry
* @author Gabriel Adauto, Wily Technology
*
* @ignore Disabled until race condition which hangs test can be fixed.
* @run build TransformerManagementThreadRemoveTests
* @run shell MakeJAR.sh basicAgent
* @run main/othervm -javaagent:basicAgent.jar TransformerManagementThreadRemoveTests TransformerManagementThreadRemoveTests
* @run shell MakeJAR.sh redefineAgent
* @run main/othervm -javaagent:redefineAgent.jar TransformerManagementThreadRemoveTests TransformerManagementThreadRemoveTests
*/
import java.util.*;
......@@ -87,7 +86,12 @@ public class TransformerManagementThreadRemoveTests
while (!testCompleted())
{
Thread.currentThread().yield();
// Effective Java - Item 51: Don't depend on the thread scheduler
// Use sleep() instead of yield().
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
}
}
assertTrue(finalCheck());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册