Since it seems like you found something for your first set of questions, I'll answer your last question:
What I am wondering is if the while loop in the MainThread waits for the SecondThread to finish processing/putting the data in the db before it starts another loop?
In your example MainThread
is never going to wait for SecondThread
to finish, it will continually execute its while loop. In your code you are creating SecondThread
inside of a while loop which will create tons of threads before your app crashes. If you want to wait for a thread to complete before doing other stuff then you can do:
SecondThread second = new SecondThread(obj);
second.start();
second.join(); //will make current thread wait until this thread finishes before proceeding
Note that a thread join in your case will essentially just make your code sequential since SecondThread will block MainThread from running.