当前位置:网站首页>3. Practice the Thread
3. Practice the Thread
2022-08-09 09:33:00 【come here my bear】
Thread, netmap download
package com.xiancheng.demo;import org.apache.commons.io.FileUtils;import java.io.File;import java.io.IOException;import java.net.URL;// Practice Thread to achieve multi-threaded synchronous download of pictures// inherit Thread class// Override the run() method// run the start() methodpublic class TestThread2 extends Thread{private String url; // network image addressprivate String name; // saved file addresspublic TestThread2(String url, String name){this.url = url;this.name = name;}public TestThread2() {}// Download the executor of the image [email protected] void run() {WebDownloader webDownloader = new WebDownloader();webDownloader.downloader(url, name);System.out.println("The downloaded file name is: " + name);}public static void main(String[] args) {TestThread2 testThread2 = new TestThread2("https://tse2-mm.cn.bing.net/th/id/OIP-C.2rQ25qnSMQHXGcHz3Rp2pAHaEo?w=277&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7","2.jpg");TestThread2 testThread3 = new TestThread2("https://tse2-mm.cn.bing.net/th/id/OIP-C.2rQ25qnSMQHXGcHz3Rp2pAHaEo?w=277&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7","3.jpg");TestThread2 testThread4 = new TestThread2("https://tse2-mm.cn.bing.net/th/id/OIP-C.2rQ25qnSMQHXGcHz3Rp2pAHaEo?w=277&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7","4.jpg");testThread2.start();testThread3.start();testThread4.start();}}class WebDownloader{// download methodpublic void downloader(String url, String name){try {FileUtils.copyURLToFile(new URL(url),new File(name));} catch (IOException e) {e.printStackTrace();System.out.println("IO exception, there is a problem with the downloader method");}}}
边栏推荐
- MySQL Checking and Filling Leaks (5) Unfamiliar Knowledge Points
- [Personal study summary] CRC verification principle and implementation
- Command line query database
- [Machine Learning] Basics of Data Science - Basic Practice of Machine Learning (2)
- 6. The File types
- 6.Map interface and implementation class
- What does the test plan include?What is the purpose and meaning?
- 第四讲 SVN
- 本体开发日记03-理解代码
- 7.FileFilter接口
猜你喜欢
常用命令之思科常用基础配置
Venture DAO Industry Research Report: Macro and Classic Case Analysis, Model Summary, Future Suggestions
列表
【个人学习总结】CRC校验原理及实现
Ontology development diary 02 - simple sparql query
[Machine Learning] Basics of Data Science - Basic Practice of Machine Learning (2)
第三方免费开放API 获取用户IP 并查询其地理位置
lateral view explode的另一种实现方式
Ontology Development Diary 01-Jena Configuration Environment Variables
性能测试包括哪些方面?分类及测试方法有哪些?
随机推荐
Global 19 Google Satellite Map Free View Download
[Personal study summary] CRC verification principle and implementation
软件测试分析流程及输出项包括哪些内容?
Golang Protobuf 处理
JS报错-Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on...
使用Protege4和CO-ODE工具构建OWL本体的实用指南-1.3版本(7.4 Annotation Properties-注释属性)
2.Collection接口
JMeter初探五-配置元件与参数化
How much do you know about the mobile APP testing process specifications and methods?
全网最全的软件测试基础知识整理(新手入门必学)
MVCC multi-version concurrency control
【面试体系知识点总结】---JVM
7.FileFilter接口
makefile学习-解决目标文件输出路径问题
5.转换流
Consolidation of Questionnaire Questions and Answers
Ovie map computer terminal and mobile terminal can not be used, is there any alternative map tool
8.递归遍历和删除案例
Venture DAO Industry Research Report: Macro and Classic Case Analysis, Model Summary, Future Suggestions
Domestic with Google earth software, see the download 19th level high-resolution satellite images so easy!