Handle OOME during threadstress finishing message
If there is an OOME that occurs after the "Finishing workers" it
caused the test to fail.
Also guard worker thread creation by try catch for OOME.
Bug: 18577101
Change-Id: I69367be0aad3f60093c02c7f63ae3c20757fb89b
diff --git a/test/004-ThreadStress/src/Main.java b/test/004-ThreadStress/src/Main.java
index 4eeae2f..9461c0b 100644
--- a/test/004-ThreadStress/src/Main.java
+++ b/test/004-ThreadStress/src/Main.java
@@ -443,13 +443,14 @@
int id = threadStress.id;
System.out.println("Starting worker for " + id);
while (threadStress.nextOperation < operationsPerThread) {
- Thread thread = new Thread(ts, "Worker thread " + id);
- thread.start();
try {
- thread.join();
- } catch (InterruptedException e) {
- }
- try {
+ Thread thread = new Thread(ts, "Worker thread " + id);
+ thread.start();
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ }
+
System.out.println("Thread exited for " + id + " with "
+ (operationsPerThread - threadStress.nextOperation)
+ " operations remaining.");
@@ -458,7 +459,14 @@
// to pass.
}
}
- System.out.println("Finishing worker");
+ // Keep trying to print "Finishing worker" until it succeeds.
+ while (true) {
+ try {
+ System.out.println("Finishing worker");
+ break;
+ } catch (OutOfMemoryError e) {
+ }
+ }
}
};
}