diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java index d524248a075..0b2c74bfc27 100644 --- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java @@ -204,7 +204,8 @@ private void waitForDeath(File watchedPid) throws CommandException { final Duration timeout = Duration.ofMillis(DEATH_TIMEOUT_MS); final Supplier deathSign; if (isLocal()) { - deathSign = () -> !ProcessUtils.isListening(addr) && !ProcessUtils.isAlive(watchedPid); + // watch process id first to reduce the number of opened ephemeral ports + deathSign = () -> !ProcessUtils.isAlive(watchedPid) && !ProcessUtils.isListening(addr); } else { deathSign = () -> !ProcessUtils.isListening(addr); } diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java index a70c18a6a49..7915dcb58a2 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java @@ -39,6 +39,7 @@ import static java.lang.System.Logger.Level.DEBUG; import static java.lang.System.Logger.Level.INFO; import static java.lang.System.Logger.Level.TRACE; +import static java.lang.System.Logger.Level.WARNING; import static java.nio.charset.StandardCharsets.ISO_8859_1; /** @@ -230,7 +231,12 @@ public static boolean waitFor(Supplier sign, Duration timeout, boolean System.out.flush(); } } - Thread.yield(); + try { + Thread.sleep(100L); + } catch (InterruptedException e) { + LOG.log(WARNING, "Interrupted while waiting", e); + break; + } } return false; } finally {