I have a for cylce that calls threads:
if(toModify[j]==1)
{
getUpdate(methods_list[j],username, password);
}
getUpdate is a method which contains something like this:
new Thread(new Runnable() {
public void run() {
// *** some operations***
}
}).start();
Through for cycle I can run each Thread simultaneously.
But if I want that each Thread starts only after the previous has stopped, can I use the following trick?
if(toModify[j]==1)
{
int returnValue = getUpdate(methods_list[j],username, password);
}
and add at the end of getUpdate method this code line (outside of run method):
return 1;
Using the above code each thread can start only if the previus has stopped? Or I’m wrong?
You can use RetrantLock
Also you will need to call join() on thread that is started from getUpdate() method.