Last active
February 6, 2018 11:57
-
-
Save Coneboy-k/5e8c16baf39d2f0f35842a9662a61990 to your computer and use it in GitHub Desktop.
KKThreadHelp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by JackSun on 2017/5/25. | |
* | |
* Connect Me. admin@jacksun.me | |
*/ | |
public class KKThreadHelp { | |
// 计算类型 | |
public enum CALCULATE_TYPE { | |
IO, // IO 密集型 | |
CALCULAT // 计算密集型 | |
} | |
// CPU 核心线程数 | |
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); | |
// 最小线程数据 | |
public final static int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors() * 1; | |
public final static long KEEP_ALIVE_TIME = 90L; | |
/** | |
* 根据类型获取最大线程数, 参考这个文章 | |
* | |
* <p>http://www.blogjava.net/bolo/archive/2015/01/20/422296.html</> | |
*/ | |
public final static int maxPoolSize(CALCULATE_TYPE calculateType) { | |
if (calculateType == null) { | |
return CPU_COUNT * 2 + 1; | |
} | |
int maxPoolSize; | |
switch (calculateType) { | |
case IO: { | |
maxPoolSize = CORE_POOL_SIZE * 2 < 64 ? 64 : CORE_POOL_SIZE * 2; | |
break; | |
} | |
case CALCULAT: | |
default: { | |
maxPoolSize = CORE_POOL_SIZE * 2 + 1; | |
break; | |
} | |
} | |
return maxPoolSize; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment