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

com.nepxion.discovery.common.thread.NamedThreadFactory Maven / Gradle / Ivy

Go to download

Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent

There is a newer version: 6.22.0
Show newest version
package com.nepxion.discovery.common.thread;

/**
 * 

Title: Nepxion Discovery

*

Description: Nepxion Discovery

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author Haojun Ren * @version 1.0 */ import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; // Copy from Alibaba Sentinel project public class NamedThreadFactory implements ThreadFactory { private AtomicInteger count = new AtomicInteger(1); private ThreadGroup group; private String namePrefix; private boolean daemon; public NamedThreadFactory(String namePrefix) { this(namePrefix, false); } public NamedThreadFactory(String namePrefix, boolean daemon) { SecurityManager securityManager = System.getSecurityManager(); this.group = securityManager != null ? securityManager.getThreadGroup() : Thread.currentThread().getThreadGroup(); this.namePrefix = namePrefix; this.daemon = daemon; } @Override public Thread newThread(Runnable runnable) { Thread thread = new Thread(group, runnable, namePrefix + "-thread-" + count.getAndIncrement(), 0); thread.setDaemon(daemon); return thread; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy