Will the for loop be part of thread.t or is it part of the main thread
Main stream. When a thread branches, the new Thread simply calls the run() method. In your case, the main thread calls start() , and then continues to run the for() method. This will most likely be called before a new thread starts. The new thread that forks only calls the run() method and any other methods used by run() .
FYI is considered a very bad practice to start a thread from an object constructor. This is a "leak" of references to the current object while it is still initializing. You should consider adding the start() method on Job or calling start() after the completion of the Job constructor.
Job job = new Job(...); job.start();
Also, since the main thread is the one that your for loop executes, it will throw an InterruptedException only if the main thread is interrupted, not the Job thread.
catch(InterruptedException e){ System.out.println("The thread has been interrupted"); }
source share