简体   繁体   中英

Start one Runnable after another

I have got 2 runnables. What is the best wait to start one after another? For instance,

Rrunnable r = new Runnable(this,initialize); 
r.execute();
unzipTask rT = new unzipTask(this);
rT.execute();

只需使用单线程执行程序 ,它就可以保证您发布到它的Runnable的顺序执行。

Simply put them into another thread:

private static Runnable combined(final Runnable r1, final Runnable r2) {
    if (r1== null) {
        return r2;
    }
    if (r2 == null) {
        return r1;
    }
    return new Runnable() {
        public void run() {
            r1.run();
            r2.run();
        }
    };
}

You can use the join() method to make one thread wait until the other has finished the execution.

More on join() here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM