private static int calculateCoreSize() { int cpuCount = Runtime.getRuntime().availableProcessors(); return calculateCoreSize(Math.max(cpuCount << 1, 2)); }
/** * Create a new instance with a generated name and specified initial thread pool settings. * * * @param coreSize the core pool size (must be greater than zero) * @param keepAliveTime the amount of time that non-core threads should linger without tasks * @param keepAliveTimeUnit the time unit for {@code keepAliveTime} * @param autoShutdown {@code true} to automatically shut down the container at VM exit, {@code false} otherwise * @return a new service container instance */ public static ServiceContainer create(int coreSize, long keepAliveTime, TimeUnit keepAliveTimeUnit, boolean autoShutdown) { return new ServiceContainerImpl(null, calculateCoreSize(coreSize), keepAliveTime, keepAliveTimeUnit, autoShutdown); }
/** * Create a new instance with a given name and specified initial thread pool settings. * * * @param name the name of the new container * @param coreSize the core pool size (must be greater than zero) * @param keepAliveTime the amount of time that non-core threads should linger without tasks * @param keepAliveTimeUnit the time unit for {@code keepAliveTime} * @param autoShutdown {@code true} to automatically shut down the container at VM exit, {@code false} otherwise * @return a new service container instance */ public static ServiceContainer create(String name, int coreSize, long keepAliveTime, TimeUnit keepAliveTimeUnit, boolean autoShutdown) { return new ServiceContainerImpl(name, calculateCoreSize(coreSize), keepAliveTime, keepAliveTimeUnit, autoShutdown); }
/** * Create a new instance with a generated name and default thread pool. * * @return a new service container instance */ public static ServiceContainer create() { return new ServiceContainerImpl(null, calculateCoreSize(), 30L, TimeUnit.SECONDS, true); }
/** * Create a new instance with a generated name and default thread pool. * * @param autoShutdown {@code true} to automatically shut down the container at VM exit, {@code false} otherwise * @return a new service container instance */ public static ServiceContainer create(boolean autoShutdown) { return new ServiceContainerImpl(null, calculateCoreSize(), 30L, TimeUnit.SECONDS, autoShutdown); }
/** * Create a new instance with a given name and default thread pool. * * @param name the name of the new container * @return a new service container instance */ public static ServiceContainer create(String name) { return new ServiceContainerImpl(name, calculateCoreSize(), 30L, TimeUnit.SECONDS, true); }
/** * Create a new instance with a given name and default thread pool. * * @param name the name of the new container * @param autoShutdown {@code true} to automatically shut down the container at VM exit, {@code false} otherwise * @return a new service container instance */ public static ServiceContainer create(String name, boolean autoShutdown) { return new ServiceContainerImpl(name, calculateCoreSize(), 30L, TimeUnit.SECONDS, autoShutdown); }
/** * Create a new instance with a generated name and specified initial thread pool settings. * * * @param coreSize the core pool size (must be greater than zero) * @param keepAliveTime the amount of time that non-core threads should linger without tasks * @param keepAliveTimeUnit the time unit for {@code keepAliveTime} * @return a new service container instance */ public static ServiceContainer create(int coreSize, long keepAliveTime, TimeUnit keepAliveTimeUnit) { return new ServiceContainerImpl(null, calculateCoreSize(coreSize), keepAliveTime, keepAliveTimeUnit, true); }
/** * Create a new instance with a given name and specified initial thread pool settings. * * * @param name the name of the new container * @param coreSize the core pool size (must be greater than zero) * @param keepAliveTime the amount of time that non-core threads should linger without tasks * @param keepAliveTimeUnit the time unit for {@code keepAliveTime} * @return a new service container instance */ public static ServiceContainer create(String name, int coreSize, long keepAliveTime, TimeUnit keepAliveTimeUnit) { return new ServiceContainerImpl(name, calculateCoreSize(coreSize), keepAliveTime, keepAliveTimeUnit, true); }