I am developing an android app that uses threads. Can you please tell me the difference between these 3 pieces of code?
First:
Thread t1 = new Thread (new Class1(param1));
Thread t2 = new Thread (new Class2(param2));
t1.start();
t2.start();
t1.join();
t2.join();
Second:
Thread t1 = new Thread (new Class1(param1));
Thread t2 = new Thread (new Class2(param2));
t1.start();
t1.join();
t2.start();
t2.join();
Third:
Thread t1 = new Thread (new Class1(param1));
t1.start();
Thread t2 = new Thread (new Class2(param2));
t2.start();
t1.join();
t2.join();
Also, how would it be different if both classes (class1 and class2) extend the same class Class?
I still need to know if both classes Class1 and Class2 extend the same class (MAINCLASS) and implement runnable, would a conflict happen? in other words can it work?
Thank you.
1) and 3) are similar: they both start 2 threads and wait for them to finish.
2) will wait for t1 to finish before starting t2 making it somewhat pointless using threads in this example