public class TestTread {
public static void main(String [] args){
String aa = Hello();
System.out.println(aa);
}
public static String Hello(){
MutliThread m1=new MutliThread("小明");
Thread t1=new Thread(m1);
t1.start();
return "小红到家了";
}
}
class MutliThread implements Runnable{
private String name;
MutliThread(String name){
this.name=name;
}
public void run(){
while(true){
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(name+"吃饭中");
}
}
}
Hello方法执行方法不必要等待
t1线程执行完才返回,吃饭过程是独立出去的一个线程,从而实现异步调用的效果。