Java测试多线程代码

  | 转载时请务必以超链接形式标明文章原文链接和作者信息及本版权声明。
原文链接:http://www.liaojl.com/archives/2008/05/java-thread.html

为了演示系统中多线程的运作,写了一个简单的测试CPU多线程处理代码。

TestCPU.java,代码如下:

public class TestCPU implements Runnable {
   public static void main(String[] args) {
       Thread a = new Thread(new TestCPU(), "a");
       Thread b = new Thread(new TestCPU(), "b");
       a.start();
       b.start();
   }

   public void run() {
       long i = 0;
       while (true) {
           i++;
           System.out.println(Thread.currentThread().getId() + ": " + i);
       }
   }
}

Leave a comment

Archives

Creative Commons License
This blog is licensed under a Creative Commons License.