技术挖掘ing

给自己加油、期待自己的成功

我的评论

class MyThread extends Thread {

private int j;

public static void main(String args[]) {
MyThread tt = new MyThread();
Inc inc = tt.new Inc();
Dec dec = tt.new Dec();
for (int i = 0; i < 2; i++) {
Thread t = new Thread(inc);
t.start();
t = new Thread(dec);
t.start();
}
}

private synchronized void inc() {
j++;
System.out.println(Thread.currentThread().getName() + "-inc:" + j);
}

private synchronized void dec() {
j--;
System.out.println(Thread.currentThread().getName() + "-dec:" + j);
}

class Inc implements Runnable {
public void run() {
for (int i = 0; i < 100; i++) {
inc();
}
}
}

class Dec implements Runnable {
public void run() {
for (int i = 0; i < 100; i++) {
dec();
}
}
}
}

My Links

Blog Stats

常用链接

留言簿(1)

随笔分类

随笔档案

文章分类

文章档案

收藏夹

链接收藏

搜索

最新评论