public class MyRunnable implements Runnable { @Override public void run() { for (int i = 0; i < 100; i++) { System.out.println("runnable实现多线程:" + i); } } }
public static void main(String[] args) { // 创建一个参数对象 MyRunnable mr1 = new MyRunnable(); // 创建一个线程对象,并将参数传递给这个线程 // 线程启动后,执行的就是参数中的run方法 Thread t1 = new Thread(mr1); t1.start(); MyRunnable mr2 = new MyRunnable(); Thread t2 = new Thread(mr2); t2.start(); }
标签:MyRunnable,Thread,实现,Runnable,new,多线程,public From: https://www.cnblogs.com/weiduaini/p/17207833.html