阅读背景:

使用Thread.run()在Enhanced循环中同时执行两个线程

来源:互联网 
public abstract class Multithread implements Runnable{
    static Thread t1 = new Thread(){
        public  synchronized void run(){
            try {
                for(;;){
                    System.out.println("java");
                    t1.sleep(300);
                }
            } catch (Exception e) {
                System.out.println("Exception"+e);
            }
        }
    };
    static Thread t2 = new Thread(){
        public  synchronized void  run(){
            try{
                for(;;){
                    System.out.println("world");
                    t2.sleep(300);
                }
            }catch(Exception e){
                System.out.println("Exception"+e);
            }
        }
    };
    public static void main(String[] args) {
        try{
            t1.start();
            t2.start();
        }catch(Exception e){
            System.out.println("Exception "+e);
        }
    }
    @Override
    public void run() {
        System.out.println("running");
    }
}
public abstract class Multithread implements Ru



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: