当前位置: 技术问答>java相关
一个简单的线程问题。
来源: 互联网 发布时间:2015-06-18
本文导语: import java.io.*; public class MyThread implements Runnable{ public void run(){ System.out.println("hello"); } public static void main(String args[]) { try{ Thread thread = new Thread("hello"); thread.run(); } catch(Exception e){ System.out.prin...
import java.io.*;
public class MyThread implements Runnable{
public void run(){
System.out.println("hello");
}
public static void main(String args[]) {
try{
Thread thread = new Thread("hello");
thread.run();
}
catch(Exception e){
System.out.println(e.toString());
}
}
}
为什么没有输出?
public class MyThread implements Runnable{
public void run(){
System.out.println("hello");
}
public static void main(String args[]) {
try{
Thread thread = new Thread("hello");
thread.run();
}
catch(Exception e){
System.out.println(e.toString());
}
}
}
为什么没有输出?
|
public class MyThread implements Runnable{
public void run(){
System.out.println("hello");
}
public static void main(String args[]) {
try{
MyThread mythread=new MyThread();
Thread thread = new Thread(mythread);
thread.start();
}
catch(Exception e){
System.out.println(e.toString());
}
}
}
public void run(){
System.out.println("hello");
}
public static void main(String args[]) {
try{
MyThread mythread=new MyThread();
Thread thread = new Thread(mythread);
thread.start();
}
catch(Exception e){
System.out.println(e.toString());
}
}
}
|
你自己的线程根本没有得到调用
|
("hello");
(new MyThread());
(new MyThread());