| 不知道这样写  规范不规范呢package it.HeiMa; 
 public class TestThrad {
 
 public static void main(String[] args) {
 Thread t = new Thread(new Me());
 t.start();
 }
 
 public static void sop(Object obj){
 System.out.println(obj);
 }
 }
 
 class Me implements Runnable{
 
 @Override
 public void run() {
 TestThrad.sop("妈妈正在煮菜!");
 try {
 throw new Exception("没盐");
 } catch (Exception e) {
 TestThrad.sop(e);
 Thread t = new Thread(new S());
 t.start();
 try {
 t.join();
 } catch (InterruptedException e1) {
 e1.printStackTrace();
 }
 }
 TestThrad.sop("妈妈继续做菜");
 }
 }
 
 class S implements Runnable{
 
 @Override
 public void run() {
 try {
 TestThrad.sop("我去买盐,稍等5秒");
 Thread.sleep(5000);
 TestThrad.sop("盐买回来了");
 } catch (InterruptedException e) {
 e.printStackTrace();
 }
 }
 
 }
 |