/** * Kills all java processes found which include the classNameFilter in their main class */ public static int killJavaProcesses(String... classNameFilters) { int count = 0; List<Long> javaProcessIds = getJavaProcessIds(classNameFilters); for (Long processId : javaProcessIds) { // lets log to the console too as this tends to show up in the junit output System.out.println("WARNING: Killing Java process " + processId); LOG.warn("Killing Java process " + processId); killProcess(processId, "-9"); count++; } return count; }
@Override public int kill() throws Exception { String customCommand = config.getKillCommand(); if (Strings.isNullOrEmpty(customCommand)) { // lets stop it LOG.info("No kill command configured so lets just try killing it with -9 " + this); return Processes.killProcess(getPid(), "-9"); } return runConfigCommandValueOrLaunchScriptWith(customCommand, "kill"); }
@Override public int stop() throws Exception { String customCommand = config.getStopCommand(); if (Strings.isNullOrEmpty(customCommand)) { // lets just kill it LOG.info("No stop command configured so lets just try killing it " + this); return Processes.killProcess(getPid(), ""); } return runConfigCommandValueOrLaunchScriptWith(customCommand, "stop"); }