关闭

同步类

标签: minathreadclassstring
469人阅读 评论(0) 收藏 举报
分类:
 
package t;


/**
 *
 * @author Vicky.H
 */
public final class Mina2 {

    public static long checkerSleepMillis = 1000;

    public static void reloadResource() throws InterruptedException {
        synchronized (Mina2.class) {
            System.out.println("done 1");
            Thread.sleep(10000);
            System.out.println("done 2");
        }
    }
    
    public static void sayHello() {
        System.out.println("Hello");
    }

    public static void main(String args[]) throws InterruptedException {
        new Mina2Thread().start();
        Mina2.sayHello();
        new Mina2Thread().start();
        
        
        new Mina2Thread2().start();
        Mina2.sayHello();
        new Mina2Thread2().start();
    }
}

class Mina2Thread extends Thread {
    
    @Override
    public void run() {
        try {
            Mina2.reloadResource();
        } catch (InterruptedException ex) {
        }
    }
}

class Mina2Thread2 extends Thread {
    
    @Override
    public void run() {
        try {
            new Mina2().reloadResource();
        } catch (InterruptedException ex) {
        }
    }
}

Hello
done 1
Hello
done 2
done 1
done 2
done 1
done 2
done 1
done 2
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1082612次
    • 积分:9313
    • 等级:
    • 排名:第1951名
    • 原创:207篇
    • 转载:37篇
    • 译文:0篇
    • 评论:66条
    最新评论