为什么我这里有3个帖子?

时间:2014-03-16 20:07:20

标签: java

嗯,我已经结束了我的智慧:我会说这是2个主题。为什么我要三个我不知道。

public class ParallelProgramming {

    public static void main(String[] args) {
        Thrd firstThread = new Thrd("FirstThread.txt");
        firstThread.start();
        Thrd secondThread = new Thrd("SecondThread.txt");        
        secondThread.start();
    } // main
} // class



public class Thrd extends Thread {
String file;
    public Thrd(String file) {
        this.file = file;
    }


    @Override
    public void run(){
        <read the file line by line>
    }
}

2 个答案:

答案 0 :(得分:5)

因为这两个线程是由启动应用程序时创建的主线程启动的(在某些情况下,它也称为UI线程)。

此线程运行main方法。

答案 1 :(得分:0)

在每个java应用程序中都有一个主线程。它执行程序。它也可以创建新的线程。

相关问题