简单的线程程序不起作用

时间:2014-03-31 10:30:55

标签: java multithreading

嗨,我是一名线程新手java程序员。我一直坚持这个简单的Java程序

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  
    }  
} 

4 个答案:

答案 0 :(得分:2)

使用start方法启动线程。调用t1.run()方法只是在同一个Thread中同步执行run方法。

t1.start();

阅读:Defining and Starting a Thread

答案 1 :(得分:1)

Java 线程由以下方法触发:

t1.start() // This starts a new thread

以下内容:

t1.run();// This calls the run method in the same thread

答案 2 :(得分:1)

线程以Thread.Start()

开头

关注线程生命周期

enter image description here

答案 3 :(得分:0)

t1.run();// just calls the run method (like any other method) in the same thread.

use t1.start() // starts a new thread.
相关问题