/
SystemUtils.java
37 lines (32 loc) · 1.14 KB
/
SystemUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package cn.trinea.android.common.util;
/**
* SystemUtils
*
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-5-15
*/
public class SystemUtils {
/** recommend default thread pool size according to system available processors, {@link #getDefaultThreadPoolSize()} **/
public static final int DEFAULT_THREAD_POOL_SIZE = getDefaultThreadPoolSize();
private SystemUtils() {
throw new AssertionError();
}
/**
* get recommend default thread pool size
*
* @return if 2 * availableProcessors + 1 less than 8, return it, else return 8;
* @see {@link #getDefaultThreadPoolSize(int)} max is 8
*/
public static int getDefaultThreadPoolSize() {
return getDefaultThreadPoolSize(8);
}
/**
* get recommend default thread pool size
*
* @param max
* @return if 2 * availableProcessors + 1 less than max, return it, else return max;
*/
public static int getDefaultThreadPoolSize(int max) {
int availableProcessors = 2 * Runtime.getRuntime().availableProcessors() + 1;
return availableProcessors > max ? max : availableProcessors;
}
}