线程池书写

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

    private static final ExecutorService executor = new ThreadPoolExecutor(50, 50,
            60L, TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(10),
            new ThreadFactory() {
     
                private final AtomicInteger threadNumber = new AtomicInteger(1);

                @Override
                public Thread newThread(Runnable r) {
     
                    return new Thread(r, "thread" + threadNumber.getAndIncrement());
                }
            });
            executor.execute(() -> entityRepository.save(entity));

你可能感兴趣的:(线程池)