Skip to content

Commit 3f111fb

Browse files
fix not check index in post
1 parent 243bd78 commit 3f111fb

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

footstone/src/main/java/com/sai/frame/footstone/base/ThreadHandlerPool.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public class ThreadHandlerPool implements Application.ActivityLifecycleCallbacks
1212

1313
static int numFlag = 1;
1414

15+
static int THREAD_POOL_SIZE_SET = 10;
16+
17+
private static int THREAD_POOL_SIZE = THREAD_POOL_SIZE_SET;
18+
1519
public static StateMachine.HandlerThreadHolder createHandlerThread(String threadName){
1620

1721
StateMachine.HandlerThreadHolder threadHolder = threads.get(threadName);
@@ -32,7 +36,10 @@ public static ThreadHandlerPool initPool(Context context){
3236
}
3337

3438
private static void createThreads(){
35-
for (int i = 0; i < 10; i++){
39+
40+
THREAD_POOL_SIZE = THREAD_POOL_SIZE_SET;
41+
42+
for (int i = 0; i < THREAD_POOL_SIZE; i++){
3643
createHandlerThread("ThreadHandlerPool_T" + i);
3744
}
3845
}
@@ -41,13 +48,19 @@ public static void post(Runnable r){
4148

4249
int num = numFlag++;
4350

51+
if (num >= THREAD_POOL_SIZE)
52+
num = 0;
53+
4454
threads.get("ThreadHandlerPool_T" + num).handlers.get(0).post(r);
4555
}
4656

4757
public static void postDelayed(Runnable r, long delayMillis){
4858

4959
int num = numFlag++;
5060

61+
if (num >= THREAD_POOL_SIZE)
62+
num = 0;
63+
5164
threads.get("ThreadHandlerPool_T" + num).handlers.get(0).postDelayed(r, delayMillis);
5265
}
5366

0 commit comments

Comments
 (0)