lyf362345 发表于 2012-12-10 14:35

账号被盗, 垃圾帖, 回收

本帖最后由 lyf362345 于 2013-08-20 09:31 编辑

账号被盗, 垃圾帖, 回收

babyblue_993 发表于 2012-12-16 22:24

没有看明白LZ想表达什么,这个API比较底层,平时难得会用到

zm_wl 发表于 2012-12-18 15:48

代码格式一下,太难看,不想看

方兆国 发表于 2013-01-13 15:12

回复 1# lyf362345


    你是求助呢还是讲解用法呢?

方兆国 发表于 2013-01-13 15:13

本帖最后由 方兆国 于 2013-01-13 15:15 编辑

public class JoinThread extends Thread {

        public static int n = 0;

        static synchronized void inc() {

                n++;

        }

        public void run() {

                for (int i = 0; i < 10; i++) {

                        try {

                                inc();

                                System.out.println(n);

                                sleep(3); // 为了使运行结果更随机,延迟3毫秒

                        } catch (Exception e) {

                        }

                }

        }

        public static void main(String[] args) throws Exception {

Thread threads[] = new Thread;

for (int i = 0; i < threads.length; i++) // 建立100个线程

{

threads = new JoinThread();

}

for (int i = 0; i < threads.length; i++) // 运行刚才建立的100个线程

{

threads.start();

}

// if (args.length > 0) {

for (int i = 0; i < threads.length; i++) // 100个线程都执行完后继续

{

threads.join(); //必须这个线程执行完,当前线程才能继续执行

}

// }

System.out.println(“n=” + JoinThread.n);

}
}我做个好人吧,给你弄好看点儿
页: [1]
查看完整版本: 账号被盗, 垃圾帖, 回收