Ramakrishna
Ramakrishna

Reputation: 4086

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?

Upvotes: 5

Views: 12891

Answers (4)

padmini
padmini

Reputation: 7

  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

Upvotes: -3

Pedro Loureiro
Pedro Loureiro

Reputation: 11514

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.

Upvotes: 1

dave.c
dave.c

Reputation: 10908

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.

Upvotes: 6

Sana
Sana

Reputation: 1

You can use join() method for this.

Upvotes: 0

Related Questions