@@ -70,6 +70,8 @@ public final class JstatdTest {
70
70
private Long jstatdPid ;
71
71
private boolean withExternalRegistry = false ;
72
72
73
+ private volatile static boolean portInUse ;
74
+
73
75
public void setServerName (String serverName ) {
74
76
this .serverName = serverName ;
75
77
}
@@ -84,20 +86,10 @@ public void setWithExternalRegistry(boolean withExternalRegistry) {
84
86
85
87
private Long waitOnTool (ProcessThread thread ) throws Throwable {
86
88
long pid = thread .getPid ();
87
-
88
- Throwable t = thread .getUncaught ();
89
- if (t != null ) {
90
- if (t .getMessage ().contains (
91
- "java.rmi.server.ExportException: Port already in use" )) {
92
- System .out .println ("Port already in use. Trying to restart with a new one..." );
93
- Thread .sleep (100 );
94
- return null ;
95
- } else {
96
- // Something unexpected has happened
97
- throw new Throwable (t );
98
- }
89
+ if (portInUse ) {
90
+ System .out .println ("Port already in use. Trying to restart with a new one..." );
91
+ return null ;
99
92
}
100
-
101
93
System .out .println (thread .getName () + " pid: " + pid );
102
94
return pid ;
103
95
}
@@ -274,6 +266,7 @@ private String[] getJstatdCmd() throws Exception {
274
266
}
275
267
276
268
private ProcessThread tryToSetupJstatdProcess () throws Throwable {
269
+ portInUse = false ;
277
270
ProcessThread jstatdThread = new ProcessThread ("Jstatd-Thread" ,
278
271
JstatdTest ::isJstadReady , getJstatdCmd ());
279
272
try {
@@ -296,6 +289,10 @@ private ProcessThread tryToSetupJstatdProcess() throws Throwable {
296
289
}
297
290
298
291
private static boolean isJstadReady (String line ) {
292
+ if (line .contains ("Port already in use" )) {
293
+ portInUse = true ;
294
+ return true ;
295
+ }
299
296
return line .startsWith ("jstatd started (bound to " );
300
297
}
301
298
0 commit comments