Java 多线程 Runnable

Java 多线程 Runnable

package thread;

/**
 * 实现Runnable接口
 * @author add by jzh 2011-12-17
 *
 */
public class HelloThread implements Runnable {
  private String name;

  public HelloThread(String name) {
    this.name = name;
  }

  @Override
  public void run() {
    for (int i = 0; i < 5; i++) {
      System.out.println(name + " = " + i);
    }
  }
}
package thread;

public class HelloTest {
  
  public static void main(String args[]) {
    Thread jzhThread = new Thread(new HelloThread("jzh"));
    Thread miThread = new Thread(new HelloThread("jiang"));
    jzhThread.start();
    miThread.start();
  }
}

 

发表回复

您的电子邮箱地址不会被公开。