Handle exception thrown in log while trying to call sun.misc.VM.maxDirectMemory() which is not available in Java 11 (#8352)

* handle exception thrown while trying to call sun.misc.VM.maxDirectMemory() which is not available in Java 11

* fixup String.format -> StringUtils.format
This commit is contained in:
David Lim 2019-08-23 02:22:41 -06:00 committed by Gian Merlino
parent 661976f266
commit d117bfb149
1 changed files with 11 additions and 2 deletions

View File

@ -25,6 +25,7 @@ import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import org.apache.druid.initialization.Initialization; import org.apache.druid.initialization.Initialization;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.lifecycle.Lifecycle; import org.apache.druid.java.util.common.lifecycle.Lifecycle;
import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.server.log.StartupLoggingConfig; import org.apache.druid.server.log.StartupLoggingConfig;
@ -78,12 +79,20 @@ public abstract class GuiceRunnable implements Runnable
final Lifecycle lifecycle = injector.getInstance(Lifecycle.class); final Lifecycle lifecycle = injector.getInstance(Lifecycle.class);
final StartupLoggingConfig startupLoggingConfig = injector.getInstance(StartupLoggingConfig.class); final StartupLoggingConfig startupLoggingConfig = injector.getInstance(StartupLoggingConfig.class);
Long directSizeBytes = null;
try {
directSizeBytes = JvmUtils.getRuntimeInfo().getDirectMemorySizeBytes();
}
catch (UnsupportedOperationException ignore) {
// querying direct memory is not supported
}
log.info( log.info(
"Starting up with processors[%,d], memory[%,d], maxMemory[%,d], directMemory[%,d].", "Starting up with processors[%,d], memory[%,d], maxMemory[%,d]%s.",
JvmUtils.getRuntimeInfo().getAvailableProcessors(), JvmUtils.getRuntimeInfo().getAvailableProcessors(),
JvmUtils.getRuntimeInfo().getTotalHeapSizeBytes(), JvmUtils.getRuntimeInfo().getTotalHeapSizeBytes(),
JvmUtils.getRuntimeInfo().getMaxHeapSizeBytes(), JvmUtils.getRuntimeInfo().getMaxHeapSizeBytes(),
JvmUtils.getRuntimeInfo().getDirectMemorySizeBytes() directSizeBytes != null ? StringUtils.format(", directMemory[%,d]", directSizeBytes) : ""
); );
if (startupLoggingConfig.isLogProperties()) { if (startupLoggingConfig.isLogProperties()) {