Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main {
    public static ExecutorService newFixedThreadPool(int threadSize) {
        if (threadSize <= 0) {
            throw new IllegalArgumentException("ThreadSize must be greater than 0!");
        }
        if (threadSize == 1) {
            return MoreExecutors.sameThreadExecutor();

        }
        return new ThreadPoolExecutor(threadSize - 1, threadSize - 1, 0L, TimeUnit.MILLISECONDS,
                new SynchronousQueue<Runnable>(), new ThreadPoolExecutor.CallerRunsPolicy());
    }
}