我在我的主方法中启动了t1线程,并希望停止主线程,但是我的t1线程仍在运行。这是否可能?如何实现?
public static void main(String[] args)
{
Thread t1=new Thread()
{
public void run()
{
while(true)
{
try
{
Thread.sleep(2000);
System.out.println("thread 1");
}
catch(Exception e)
{}
}
}
};
t1.start();
}
System.exit(0);
会停止整个应用程序,那么你如何知道线程t1
仍在运行? - Abimaran Kugathasan