Java(29):进程与线程
public class MyThread extends Thread { public static void main(String[] args) { // 创建线程对象mt1并启动 MyThread mt1 = new MyThread("肖申克的救赎"); mt1.start(); // 创建线程对象mt2并启动 MyThread mt2 = new MyThread("当幸福来敲门"); mt2.start(); } private String name; public MyThread(String name) { this.name = name; } @Override public void run() { for (int i=0; i<=100; i++) { System.out.println(name+"下载了"+i+"%"); } } }
public class DownLoad implements Runnable { private String name; public DownLoad(String name) { this.name = name; } public static void main(String[] args) { DownLoad downLoad1 = new DownLoad("当幸福来敲门"); Thread t1 = new Thread(downLoad1); Thread t2 = new Thread(new DownLoad("肖申克的救赎")); t1.start(); t2.start(); } @Override public void run() { for (int i=0; i<=100; i++) { System.out.println(name+"下载了"+i+"%"); } } }
参考博客:https://blog.csdn.net/renlianggee/article/details/90029746