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

com.ziqni.transformer.test.concurrent.ZiqniThreadFactory Maven / Gradle / Ivy

There is a newer version: 2.0.12-RC1
Show newest version
/*
 * Copyright (c) 2022. ZIQNI LTD registered in England and Wales, company registration number-09693684
 */
package com.ziqni.transformer.test.concurrent;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class ZiqniThreadFactory implements ThreadFactory {

    private static final AtomicInteger poolNumber = new AtomicInteger(1);
    private final ThreadGroup group;
    private final AtomicInteger threadNumber = new AtomicInteger(1);
    private final String namePrefix;

    public ZiqniThreadFactory(String threadNamePrefix) {

        SecurityManager s = System.getSecurityManager();

        group = (s != null)
                ? s.getThreadGroup() :
                Thread.currentThread().getThreadGroup();

        namePrefix = threadNamePrefix + "-" + poolNumber.getAndIncrement() + "-thread-";
    }

    public Thread newThread(Runnable r) {
        Thread t = new Thread(group, r,
                namePrefix + threadNumber.getAndIncrement(),
                0);
        if (t.isDaemon())
            t.setDaemon(false);
        if (t.getPriority() != Thread.NORM_PRIORITY)
            t.setPriority(Thread.NORM_PRIORITY);
        return t;
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy