*** 创建多线程的三种方式

继承Thread类,重写Run方法
实现Runnable接口,重写run方法实现callable接口,重写call方法继承Thread类,重写run方法,类名.start()启动线程

实现Runable接口,重写run方法,new Thread(类对象).start();
**

public class commons extends Thread{//run是线程的入口点public void download(String url,String name){try {FileUtils.copyURLToFile(new URL(url), new File(name));} catch (MalformedURLException e) {e.printStackTrace();System.out.println("不合法的路径");} catch (IOException e) {e.printStackTrace();System.out.println("图片下载失败");}}

}

//开启下载:
public class ThreadDownload extends Thread {
private String url; //远程路径
private String name; //存储名字

public ThreadDownload(String url,String name)
{
this.url=url;
this.name=name;
}
public void run()
{
commons wd=new commons();
wd.download(url, name);
}

public static void main(String[]args)
{
ThreadDownload td =new ThreadDownload("https://cache.yisu.com/upload/information/20200311/58/227722.jpg","D:/d/a.jpg");
ThreadDownload td2=new ThreadDownload("https://cache.yisu.com/upload/information/20200311/58/227723.jpg","D:/d/b.jpg");
ThreadDownload td3=new ThreadDownload("https://cache.yisu.com/upload/information/20200311/58/227724.jpg","c.jpg");

//启动三个线程td.start();td2.start();td3.start();

}
}