i have got a problem, lets say i have got code like that:
public static void main(String[] args)
{
startMethod1();
startMethod2();
}
Now, if startMethod1 method is very big and takes a lot of time to execute it, startMethod2 is started before startMethod1 has been finished.
How to make those methods execute 1 by 1?
This will never happen. You can start threads in
startMethod1which could still be running asstartmethod2starts.startMethod2cannot start beforestartMethod1unlessstartMethod1callsstartMethod2If you want to wait until the threads in startmethod1 have finished you have to
Thread.join()them or useExecutorService.awaitTermination()Just as you have written the code.