Often the user of a program does something that causes the program to do some task that is time-consuming. In this situation, you may prefer the user to have the ability to get on with something else at the same time as the time-consuning task. In Java, you can put the time-consuming task into a separate thread of execution.
It is easy to start another thread: you just need to create an object of the class Thread (from the package java.lang), and execute its start method. So, suppose a method, e.g., the main method of a program, contains:
0791: Thread tThread = new Thread(); 0792: ... 0793: tThread.start();
The the call of start does two things:
This is not so exciting as it sounds because java.lang.Thread's run method does nothing because it has a null body: it stops executing straightaway. And so we are just left with the thread of execution that is executing the main method.