-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadExecutor.java
More file actions
39 lines (30 loc) · 964 Bytes
/
ThreadExecutor.java
File metadata and controls
39 lines (30 loc) · 964 Bytes
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
38
39
import android.support.annotation.NonNull;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadExecutor implements Executor {
private ExecutorService executor;
public ThreadExecutor() {
int coreCount = Runtime.getRuntime().availableProcessors();
executor = Executors.newFixedThreadPool(coreCount);
}
public void executeTask(Runnable task) {
executor.execute(task);
}
@Override
public void execute(@NonNull final Runnable command) {
new Thread(new Runnable() {
@Override
public void run() {
command.run();
}
}).start();
}
}
public class UIExecutor implements Executor {
private Handler handler = new Handler(Looper.getMainLooper());
@Override
public void execute(@NonNull Runnable command) {
handler.post(command);
}
}