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

com.aliyun.datahub.client.common.ForkJoinPoolFactory Maven / Gradle / Ivy

The newest version!
package com.aliyun.datahub.client.common;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;

public abstract class ForkJoinPoolFactory {
    private static ForkJoinPool.ForkJoinWorkerThreadFactory getFactory(String threadName) {
        ForkJoinPool.ForkJoinWorkerThreadFactory factory = new ForkJoinPool.ForkJoinWorkerThreadFactory() {
            @Override
            public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
                final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
                worker.setName(threadName + "-" + worker.getPoolIndex());
                return worker;
            }
        };
        return factory;
    }

    public static ForkJoinPool getPool(int parallelism, String threadName) {
        ForkJoinPool.ForkJoinWorkerThreadFactory factory = getFactory(threadName);
        return new ForkJoinPool(
                parallelism,
                factory,
                null,
                false);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy