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

org.wildfly.clustering.context.DefaultThreadFactory Maven / Gradle / Ivy

There is a newer version: 33.0.2.Final
Show newest version
/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.context;

import java.util.concurrent.ThreadFactory;
import java.util.function.Supplier;

import org.jboss.threads.JBossThreadFactory;
import org.wildfly.security.ParametricPrivilegedAction;
import org.wildfly.security.manager.WildFlySecurityManager;

/**
 * Default {@link ThreadFactory} implementation that applies a specific context {@link ClassLoader}.
 * @author Paul Ferraro
 */
public class DefaultThreadFactory extends ContextualThreadFactory {

    private enum ThreadPoolFactory implements ParametricPrivilegedAction> {
        INSTANCE;

        @Override
        public ThreadFactory run(Supplier group) {
            return new JBossThreadFactory(group.get(), Boolean.FALSE, null, "%G - %t", null, null);
        }
    }

    public DefaultThreadFactory(Class targetClass) {
        this(targetClass, new Supplier<>() {
            @Override
            public ThreadGroup get() {
                return new ThreadGroup(targetClass.getSimpleName());
            }
        });
    }

    DefaultThreadFactory(Class targetClass, Supplier group) {
        this(WildFlySecurityManager.doUnchecked(group, ThreadPoolFactory.INSTANCE), targetClass);
    }

    public DefaultThreadFactory(ThreadFactory factory) {
        this(factory, factory.getClass());
    }

    private DefaultThreadFactory(ThreadFactory factory, Class targetClass) {
        super(factory, WildFlySecurityManager.getClassLoaderPrivileged(targetClass), ContextClassLoaderReference.INSTANCE);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy