Skip to content Skip to sidebar Skip to footer

How To Run One Thread After Complete Another Thread

I want to run two threads r1, and r2. First start the r1 and after completion of r1, start r2 (only after the completion r1). How can this be done, two threads, one after another?

Solution 1:

My answer here has an example using a Thread and a Handler. This method might be useful if you wanted to perform some UI updates in between the threads running.

Solution 2:

Why don't you do all the tasks you want in one single thread? This way they will be "naturally" one after the other.

The way to implement this depends on what type of tasks you want to do and how you pass them the information they require to start.

Solution 3:

You can use join() method for this.

Solution 4:

  1. Make a Boolean variable with initially false
  2. Start the first thread
  3. After completion of the entire 1st thread execution make the Boolean value to true
  4. Don't start second thread util/unless the flag becomes true

Post a Comment for "How To Run One Thread After Complete Another Thread"