Hi, I'm a novice java programmer towards thread. And I'm stuck on this simple Java program
public class Multi extends Thread{
public void run() {
try{
System.out.println("running...");
}
catch(Exception e){
System.out.print(e);
}
}
public static void main(String[] args){
Multi t1=new Multi();
t1.run();//fine, but does not start a separate call stack
}
}
Threads are started using the start method. Calling t1.run()
method just synchronously executes the run
method within the same Thread.
t1.start();
Java threads are triggered by the following method:
t1.start() // This starts a new thread
While the following:
t1.run();// This calls the run method in the same thread
t1.run();// just calls the run method (like any other method) in the same thread.
use t1.start() // starts a new thread.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.