Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 主方法中的线程启动_Java_Multithreading_Main - Fatal编程技术网

Java 主方法中的线程启动

Java 主方法中的线程启动,java,multithreading,main,Java,Multithreading,Main,我试图在main方法内部启动一个线程,但在启动线程时它不会调用run方法。我认为这可能与在一个线程中启动一个线程有关: package com.audiack.theForest; public class theForestThread implements Runnable { private static int theBeginningTimes = 0; private static TheBeginning theBeginning = new TheBeginni

我试图在main方法内部启动一个线程,但在启动线程时它不会调用run方法。我认为这可能与在一个线程中启动一个线程有关:

package com.audiack.theForest;

public class theForestThread implements Runnable {
    private static int theBeginningTimes = 0;
    private static TheBeginning theBeginning = new TheBeginning();
    public static void main(String args[]){
        Thread thread = new Thread();
        thread.start();
    }
    @Override
    public void run() {
        theBeginning.start(theBeginningTimes);
        theBeginningTimes++;
    }
}

您正在启动的
线程
没有
可运行
,即使用
线程
运行()
实现,该实现为空

您需要将类的实例传递给新的
线程
对象的构造函数

public static void main(String args[]){
    Thread thread = new Thread(new theForestThread());
    thread.start();
}

您正在启动的
线程
没有
可运行
,即使用
线程
运行()
实现,该实现为空

您需要将类的实例传递给新的
线程
对象的构造函数

public static void main(String args[]){
    Thread thread = new Thread(new theForestThread());
    thread.start();
}
试试下一个:

new Thread(new(theForestThread())).start();
请参阅

中的详细信息,然后尝试下一步:

new Thread(new(theForestThread())).start();
在中查看更多信息