当前位置:网站首页>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");}}}
边栏推荐
猜你喜欢
Django实现对数据库数据增删改查(一)
条件和递归
JMeter初探五-配置元件与参数化
本体开发日记02-sparql简单查询
Global 19 Google Satellite Map Free View Download
What are the basic concepts of performance testing?What knowledge do you need to master to perform performance testing?
米斗APP逆向分析
本体开发日记04-努力理解protege的某个方面
Anti App so层对抗分析
Ontology Development Diary 05-Strive to Understand SWRL (Part 2)
随机推荐
接口设计
Ontology Development Diary 03 - When debugging is in progress
6.Map接口与实现类
6. The File types
JS-常用方法整理
软件测试流程包括哪些内容?测试方法有哪些?
选择黑盒测试用例设计方法的综合策略方案总结
Redis Basics
软件测试外包公司怎么样?有什么好处和坏处?为什么没人去?
本体开发日记05-努力理解SWRL(RDF Concrete Syntax)
功能自动化测试实施的原则以及方法有哪些?
map去重代码实现
【机器学习】数据科学基础——机器学习基础实践(二)
软件测试分析流程及输出项包括哪些内容?
软件测试面试思路技巧和方法分享,学到就是赚到
Environment build onnxruntime 】
真·鸡汤文
搭建Tigase进行二次开发
使用Protege4和CO-ODE工具构建OWL本体的实用指南-1.3版本(4.Building An OWL Ontology)
MySQL Leak Detection and Filling (2) Sorting and Retrieval, Filtering Data, Fuzzy Query, Regular Expression