Android AsyncTask 源码摘录--线程安全线程池方式
代码一
new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... arg) { //do somethings return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
代码二
AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { public void run() { long start = System.currentTimeMillis(); //do somethings long cost = System.currentTimeMillis() - start; if (cost > 100) { Log.i(TAG, "init cost: " + cost); } } });
代码三
AsyncTask.execute(new Runnable() {// use SerialExecutor to sync @Override public void run() { Log.i(TAG, "..... start"); //do somethings } });
版权声明:如无特殊标注,文章均为本站原创,转载时请以链接形式注明文章出处。
评论