equal
deleted
inserted
replaced
187 } |
187 } |
188 } |
188 } |
189 |
189 |
190 private void checkMainClass(Process p, String expectedMainClass) { |
190 private void checkMainClass(Process p, String expectedMainClass) { |
191 String mainClass = PROCESS_HELPER.getMainClass(Long.toString(p.pid())); |
191 String mainClass = PROCESS_HELPER.getMainClass(Long.toString(p.pid())); |
|
192 // getMainClass() may return null, e.g. due to timing issues. |
|
193 // Attempt some limited retries. |
|
194 if (mainClass == null) { |
|
195 System.err.println("Main class returned by ProcessHelper was null."); |
|
196 // sleep time doubles each round, altogether, wait no longer than 1 sec |
|
197 final int MAX_RETRIES = 10; |
|
198 int retrycount = 0; |
|
199 long sleepms = 1; |
|
200 while (retrycount < MAX_RETRIES && mainClass == null) { |
|
201 System.err.println("Retry " + retrycount + ", sleeping for " + sleepms + "ms."); |
|
202 try { |
|
203 Thread.sleep(sleepms); |
|
204 } catch (InterruptedException e) { |
|
205 // ignore |
|
206 } |
|
207 mainClass = PROCESS_HELPER.getMainClass(Long.toString(p.pid())); |
|
208 retrycount++; |
|
209 sleepms *= 2; |
|
210 } |
|
211 } |
192 p.destroyForcibly(); |
212 p.destroyForcibly(); |
193 if (!expectedMainClass.equals(mainClass)) { |
213 if (!expectedMainClass.equals(mainClass)) { |
194 throw new RuntimeException("Main class is wrong: " + mainClass); |
214 throw new RuntimeException("Main class is wrong: " + mainClass); |
195 } |
215 } |
196 } |
216 } |