All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.actuate.health.checker.HealthCheckerExecutor Maven / Gradle / Ivy

The newest version!
package org.zodiac.actuate.health.checker;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.health.Health;
import org.zodiac.commons.concurrent.thread.EnhancedThreadPoolExecutor;
import org.zodiac.sdk.toolkit.concurrent.thread.NamedThreadFactory;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class HealthCheckerExecutor {
    private static Logger logger = LoggerFactory.getLogger(HealthCheckerExecutor.class);

    private static final ThreadPoolExecutor THREAD_POOL_REF = createThreadPoolExecutor();

    public static Future submitTask(Callable callable) {
        return THREAD_POOL_REF.submit(callable);
    }

    /**
     * Create thread pool to execute health check.
     * 
     * @return thread pool to execute health check.
     */
    private static ThreadPoolExecutor createThreadPoolExecutor() {
        int corePoolSize = 1, maximumPoolSize = 1;
        String threadPoolName = "health-checker";
        logger.info("Create health-check thread pool, corePoolSize: {}, maxPoolSize: {}.", corePoolSize,
            maximumPoolSize);
        return new EnhancedThreadPoolExecutor(corePoolSize, maximumPoolSize, 30, TimeUnit.SECONDS,
            new SynchronousQueue(), new NamedThreadFactory(threadPoolName),
            new ThreadPoolExecutor.CallerRunsPolicy(), threadPoolName, threadPoolName);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy