AsyncTask alternative with Runnable and CountdownLatch What is wrong with this pattern which emulates AsyncTask functionality?:

// on the UI thread
final CountDownLatch latch = new CountDownLatch(1);
onPreexecuteWrapper();
new Thread(new Runnable() {
        doInBackgroundWrapper();
        latch.countDown();
    }
}).start();

new Thread(new Runnable() {
    @Override
    public void run() {
        try {
                latch.await();
        } catch (InterruptedException e) {
            Logger.error(TAG, "Not good.");
        }

    context.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            onPostExecuteWrapper();
        }
    });
}
}).start();


Here's what I think is wrong:


Two threads -> more resources (I didn't compare actually, just guessing).
No progress update functionality.
Appears to be stinky.
First thing that is wrong is that you are reinventing a wheel.

Second why not ditch the CountDownLatch and do context.runOnUiThread directly in the first runnable instead?

// on the UI thread

onPreexecuteWrapper();
new Thread(new Runnable() {
    @Override
    public void run() {
        doInBackgroundWrapper();
        context.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                onPostExecuteWrapper();
            }
        });
    }
}).start();


Last thing is that it's better to use an Executor and ThreadPool than to spawn new threads.