I create 4 threads to do 4 operations. When all threads complete execution,I want to notify main thread. How to know if all thread complete?
Here is my code:
public class TestActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
/*
* create 4 threads to do 4 operations
* */
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {} // do operation 1
});
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {} // do operation 2
});
Thread thread3 = new Thread(new Runnable() {
@Override
public void run() {} // do operation 3
});
Thread thread4 = new Thread(new Runnable() {
@Override
public void run() {} // do operation 4
});
thread1.start();
thread2.start();
thread3.start();
thread4.start();
}
}