Android AsyncTask 源码摘录--线程安全线程池方式

sancaiodm Android源码摘录 2021-09-24 1173 0

代码一

        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
            }
        });


评论