/* Make sure all part of the app use the same method to get dates, asdifferentmethodscouldproducedifferentresults
*/ privatestaticlong epoch() { returnnew Date().getTime();
}
publicvoid waitAppTerminate() { // This code is modeled after tail end of ProcessTools.getOutput(). try { // If the app hangs, we don't want to wait for the to test timeout. if (!appProcess.waitFor(Utils.adjustTimeout(appWaitTime), TimeUnit.SECONDS)) {
appProcess.destroy();
appProcess.waitFor();
}
outPumperThread.join();
errPumperThread.join();
} catch (InterruptedException e) { Thread.currentThread().interrupt(); // pass
}
}
/** *Theapptouchesthelockfilewhenit'sstarted *waitwhileithappens.Callerhavetodeletelockonwaiterror. * *@paramtimeouttimeoutinseconds *@throwsjava.io.IOException
*/ publicvoid waitAppReadyOrCrashed(long timeout) throws IOException { // adjust timeout for timeout_factor and convert to ms
timeout = Utils.adjustTimeout(timeout) * 1000; long here = epoch(); while (true) { // Check for crash or lock modification now, and immediately after sleeping for spinDelay each loop. if (!appProcess.isAlive()) { if (forceCrash) { return; // This is expected. Just return.
} else { thrownew IOException("App exited unexpectedly with " + appProcess.exitValue());
}
}
// Live process should touch lock file every second long lm = lastModified(lockFileName); if (lm > lockCreationTime) { break;
}
long timeTaken = epoch() - here; if (timeTaken > timeout) { thrownew IOException("Timeout: app not started or crashed in " + timeTaken + "ms");
} try { Thread.sleep(spinDelay);
} catch (InterruptedException ex) { // pass
}
}
}
/** *Analyzeanenvironmentandprepareacommandlineto *runtheapp,appnameshouldbeaddedexplicitly
*/ private List<String> runAppPrepare(String[] vmArguments) {
List<String> cmd = new ArrayList<>();
cmd.add(JDKToolFinder.getTestJDKTool("java"));
Collections.addAll(cmd, vmArguments); if (forceCrash) {
cmd.add("-XX:+CreateCoredumpOnCrash"); // We need to find libLingeredApp.so for the crash() native method
cmd.add("-Djava.library.path=" + System.getProperty("java.library.path"));
}
if (useDefaultClasspath()) { // Make sure we set correct classpath to run the app
cmd.add("-cp");
String classpath = System.getProperty("test.class.path");
cmd.add((classpath == null) ? "." : classpath);
}
runAddAppName(cmd);
cmd.add(lockFileName); if (forceCrash) {
cmd.add("forceCrash"); // Let the subprocess know to force a crash
}
printCommandLine(cmd);
ProcessBuilder pb = new ProcessBuilder(cmd); if (forceCrash) { // If we are going to force a core dump, apply "ulimit -c unlimited" if we can.
pb = CoreUtils.addCoreUlimitCommand(pb);
} // ProcessBuilder.start can throw IOException
appProcess = pb.start();
/** *Deletelockfilethatsignalsapptoterminate,then *waituntilappisactuallyterminated. *@throwsIOException
*/ publicvoid stopApp() throws IOException {
deleteLock(); // The startApp() of the derived app can throw // an exception before the LA actually starts if (appProcess != null) {
waitAppTerminate();
finishApp();
int exitcode = appProcess.exitValue(); if (exitcode != 0) { thrownew IOException("LingeredApp terminated with non-zero exit code " + exitcode);
}
}
}
/** *Highlevelinterfacefortestwriters
*/
/** *Factorymethodthatstartspre-createdLingeredApp *locknameisautogenerated *Usershouldprovideexactoptionstorunapp.Mightuse#Utils.getTestJavaOpts()tosetdefaulttestoptions. *@paramjvmOpts-theexactvmoptionsusedtostartLingeredApp *@paramtheApp-apptostart *@throwsIOException
*/ publicstaticvoid startAppExactJvmOpts(LingeredApp theApp, String... jvmOpts) throws IOException { long t1 = System.currentTimeMillis();
theApp.createLock(); try {
theApp.runAppExactJvmOpts(jvmOpts);
theApp.waitAppReadyOrCrashed();
} catch (Exception ex) { boolean alive = theApp.getProcess() != null && theApp.getProcess().isAlive();
System.out.println("LingeredApp failed to start or failed to crash. isAlive=" + alive + ": " + ex); // stopApp in case it is still alive, may be able to get output: if (alive) {
theApp.stopApp();
}
alive = theApp.getProcess() != null && theApp.getProcess().isAlive(); if (!alive) {
theApp.finishApp(); // Calls getOutput(), fails if still alive
}
theApp.deleteLock(); throw ex;
} finally { long t2 = System.currentTimeMillis();
System.out.println("LingeredApp startup took " + (t2 - t1) + "ms");
checkForDumps();
}
}
/** *Showanydumpfilesofinterestinthecurrentdirectory.
*/ publicstaticvoid checkForDumps() {
System.out.println("Check for hs_err_pid/core/mdmp files:"); int count = 0;
FilenameFilter filter = (dir, file) -> (file.startsWith("hs_err_pid") || file.startsWith("core") || file.endsWith("mdmp")); for (File f : new File(".").listFiles(filter)) { long fileSize = f.length();
System.out.println(f + " " + (fileSize / 1024 / 1024) + "mb (" + fileSize + " bytes)");
count++;
} if (count == 0) {
System.out.println("None.");
}
}
publicstaticvoid stopApp(LingeredApp app) throws IOException { if (app != null) { // LingeredApp can throw an exception during the intialization, // make sure we don't have cascade NPE
app.stopApp();
}
}
publicstaticboolean isLastModifiedWorking() { boolean sane = true; try { long lm = lastModified("."); if (lm == 0) {
System.err.println("SANITY Warning! The lastModifiedTime() doesn't work on this system, it returns 0");
sane = false;
}
long now = epoch(); if (lm > now) {
System.err.println("SANITY Warning! The Clock is wrong on this system lastModifiedTime() > getTime()");
sane = false;
}
setLastModified(".", epoch()); long lm1 = lastModified("."); if (lm1 <= lm) {
System.err.println("SANITY Warning! The setLastModified doesn't work on this system");
sane = false;
}
} catch(IOException e) {
System.err.println("SANITY Warning! IOException during sanity check " + e);
sane = false;
}
try {
Object steadyStateObj = new Object(); synchronized(steadyStateObj) {
startSteadyStateThread(steadyStateObj); if (forceCrash) {
System.loadLibrary("LingeredApp"); // location of native crash() method
crash();
} while (Files.exists(path)) { // Touch the lock to indicate our readiness
setLastModified(theLockFileName, epoch()); Thread.sleep(spinDelay);
}
}
} catch (IOException ex) { // Lock deleted while we are setting last modified time. // Ignore the error and let the app exit. if (Files.exists(path)) { // If the lock file was not removed, return an error.
System.err.println("LingeredApp IOException: lock file still exists");
System.exit(4);
}
} catch (Exception ex) {
System.err.println("LingeredApp ERROR: " + ex); // Leave exit_code = 1 to Java launcher
System.exit(3);
}
System.exit(0);
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.25 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.