Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Determines proper size for a thread pool based upon the number of cores
     * and a default blocking coefficient of 0.9.
     * <p>
     * Based upon code from "Programming Concurrency on the JVM", page 23.
     * 
     * @return poolSize
     * @see #determineThreadPoolSize(double)
     */
    public static int determineThreadPoolSize() {
        return determineThreadPoolSize(0.9);
    }

    /**
     * Determines proper size for a thread pool based upon the number of cores
     * and the specified blocking coefficient.
     * <p>
     * Based upon code from "Programming Concurrency on the JVM", page 23.
     * 
     * @param blockingCoefficient
     * @return poolSize
     * @see #determineThreadPoolSize()
     */
    public static int determineThreadPoolSize(final double blockingCoefficient) {
        final int numberOfCores = Runtime.getRuntime().availableProcessors();
        final int poolSize = (int) (numberOfCores / (1 - blockingCoefficient));
        return poolSize;
    }
}