Created
July 24, 2020 16:02
-
-
Save lfmunoz/6cc9cb147a2631ba43602fa31fa5f9b7 to your computer and use it in GitHub Desktop.
Monitor Thread Executor Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.micrometer.core.instrument.Metrics | |
import io.micrometer.core.instrument.Tags | |
import com.google.common.util.concurrent.ThreadFactoryBuilder | |
import java.util.concurrent.ExecutorService | |
import java.util.concurrent.SynchronousQueue | |
import java.util.concurrent.ThreadPoolExecutor | |
import java.util.concurrent.TimeUnit | |
@Bean(destroyMethod = "shutdown") | |
fun connectionExecutorService(): ExecutorService { | |
val maxThreads = (applicationProperties.availableCores * 2).coerceAtLeast(2) | |
val threadFactory = ThreadFactoryBuilder().setNameFormat("rabbitConn-%s").setDaemon(true).build() | |
val threadPoolExec = ThreadPoolExecutor( | |
1, | |
maxThreads, | |
60L, | |
TimeUnit.SECONDS, | |
SynchronousQueue(), | |
threadFactory, | |
ThreadPoolExecutor.CallerRunsPolicy() | |
) | |
Metrics.gauge(RABBIT_THREADS_CONNECTION, Tags.of(TAG_KEY_TYPE, "queueSize"), threadPoolExec, { it.queue.size.toDouble() }) | |
Metrics.gauge(RABBIT_THREADS_CONNECTION, Tags.of(TAG_KEY_TYPE, "activeCount"), threadPoolExec, { it.activeCount.toDouble() }) | |
Metrics.gauge(RABBIT_THREADS_CONNECTION, Tags.of(TAG_KEY_TYPE, "poolSize"), threadPoolExec, { it.poolSize.toDouble() }) | |
Metrics.gauge(RABBIT_THREADS_CONNECTION, Tags.of(TAG_KEY_TYPE, "taskCount"), threadPoolExec, { it.taskCount.toDouble() }) | |
return threadPoolExec | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ArrayBlockingQueue queue = new ArrayBlockingQueue(2);
LinkedBlockingQueue