test/jdk/sun/tools/jcmd/TestProcessHelper.java
changeset 58143 b35771556cd0
parent 55386 2f4e214781a1
child 58265 577e17cab93f
equal deleted inserted replaced
58142:24df796eef3d 58143:b35771556cd0
   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     }