标签:java his tst span java多线程 开始 rgs nts demo
public class MultiThread { public static void main(String[] args) { Thread t1 = new Thread(new ThreadDemo("线程1")); Thread t2 = new Thread(new ThreadDemo("线程2")); t1.start(); t2.start(); } } class ThreadDemo implements Runnable { private String name; public ThreadDemo(String name) { this.name = name; } @Override public void run() { for (int i = 0; i < 5; i++) { System.out.println("线程 :" + name + "开始干活"); try { //休息1秒模拟干活 Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
[JAVA]JAVA多线程实现方法之——实现Runnable接口
标签:java his tst span java多线程 开始 rgs nts demo
原文地址:https://www.cnblogs.com/zhengxl5566/p/10329958.html