ExecutorService的基本使用
程序员文章站
2022-03-24 12:37:18
...
不要再老是用野线程 new Thread(new Runnable(){})啦
线程池你值得拥有:
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.execute(new Runnable() {
public void run() {
}
});
executorService.shutdown();
子线程中如果要更新UI,也可以不用handler,直接这样
runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(doc.body().text());
}
});
同时异步线程的实现方式还有
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
}
}.execute();