package com.yfd.platform.uavsystem.conf.thread;

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

/**
 * 线程池使用
 * @author lwt
 */
public class MyThreadFactory implements ThreadFactory {

        private final String namePrefix;
        private final AtomicInteger atomicInteger =new AtomicInteger(1);

        public MyThreadFactory(String threadName){
            this.namePrefix=threadName+"-thread-";
        }

        @Override
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r, namePrefix + atomicInteger.getAndIncrement());
            if(thread.isDaemon()){
                thread.setDaemon(false);
            }
            if(thread.getPriority() != Thread.NORM_PRIORITY){
                thread.setPriority(Thread.NORM_PRIORITY);
            }
            return thread;
        }
    }