多线程

来源:互联网 发布:最终幻想14优化 编辑:程序博客网 时间:2024/05/31 00:39

这周学了多线程,单线程创建多线程创建。

public class bbb

{
public static void main(String[] args){
MyThread myThread=new MyThread();
myThread.run();
while(true){
System.out.println("Main方法在运行");
}
}
}
class MyThread{
public void run(){
while(true){
System.out.println("MyThread类的run()方法在运行");
}
}

}


像死循环一样


public class ccc{
public static void main(String[] args){ 
MyThread myThread = new MyThread();
myThread.start();
while(true){
System.out.println("Main方法在运行");
}
}
}
class MyThread extends Thread
{
public void run(){
while(true)
{
System.out.println("MyThread类的run()方法在运行");
}
}
}