@@ -41,6 +41,53 @@ public final class ThreadUtils {
41
41
private static final int CPU_CORE_POOL_SIZE = Math .max (2 , Math .min (CPU_COUNT - 1 , 4 ));
42
42
private static final int CPU_MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1 ;
43
43
44
+ /**
45
+ * Return whether the thread is the main thread.
46
+ *
47
+ * @return {@code true}: yes<br>{@code false}: no
48
+ */
49
+ public static boolean isMainThread () {
50
+ return Looper .myLooper () == Looper .getMainLooper ();
51
+ }
52
+
53
+ /**
54
+ * Return
55
+ * @param size
56
+ * @return
57
+ */
58
+ public static ExecutorService getFixedPool (@ IntRange (from = 1 ) final int size ) {
59
+ return getPoolByTypeAndPriority (size );
60
+ }
61
+
62
+ public static ExecutorService getFixedPool (@ IntRange (from = 1 ) final int size ,
63
+ @ IntRange (from = 1 , to = 10 ) final int priority ) {
64
+ return getPoolByTypeAndPriority (size , priority );
65
+ }
66
+
67
+ public static ExecutorService getSinglePool () {
68
+ return getPoolByTypeAndPriority (TYPE_SINGLE );
69
+ }
70
+
71
+ public static ExecutorService getSinglePool (@ IntRange (from = 1 , to = 10 ) final int priority ) {
72
+ return getPoolByTypeAndPriority (TYPE_SINGLE , priority );
73
+ }
74
+
75
+ public static ExecutorService getIoPool () {
76
+ return getPoolByTypeAndPriority (TYPE_CACHED );
77
+ }
78
+
79
+ public static ExecutorService getIoPool (@ IntRange (from = 1 , to = 10 ) final int priority ) {
80
+ return getPoolByTypeAndPriority (TYPE_CACHED , priority );
81
+ }
82
+
83
+ public static ExecutorService getCpuPool () {
84
+ return getPoolByTypeAndPriority (TYPE_CPU );
85
+ }
86
+
87
+ public static ExecutorService getCpuPool (@ IntRange (from = 1 , to = 10 ) final int priority ) {
88
+ return getPoolByTypeAndPriority (TYPE_CPU , priority );
89
+ }
90
+
44
91
public static <T > void executeByFixed (@ IntRange (from = 1 ) final int size , final Task <T > task ) {
45
92
execute (getPoolByTypeAndPriority (size ), task );
46
93
}
@@ -284,10 +331,6 @@ public static void cancel(final Task task) {
284
331
task .cancel ();
285
332
}
286
333
287
- public static boolean isMainThread () {
288
- return Looper .myLooper () == Looper .getMainLooper ();
289
- }
290
-
291
334
private static <T > void execute (final ExecutorService pool , final Task <T > task ) {
292
335
executeWithDelay (pool , task , 0 , TimeUnit .MILLISECONDS );
293
336
}
0 commit comments