当前位置:网站首页>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");}}}
边栏推荐
- 本体开发日记04-努力理解protege的某个方面
- 游戏测试的概念是什么?测试方法和流程有哪些?
- Global 19 Google Satellite Map Free View Download
- Django实现对数据库数据增删改查(二)
- 年薪40W测试工程师成长之路,你在哪个阶段?
- Anti App so层对抗分析
- MySQL Leak Detection and Filling (2) Sorting and Retrieval, Filtering Data, Fuzzy Query, Regular Expression
- Consolidation of Questionnaire Questions and Answers
- try catch 对性能影响
- 7.Collections tool class
猜你喜欢
Command line query database
记录一次被入侵5900端口经历
Domestic Google earth, terrain analysis seconds kill with the map software
白盒测试的概念、目的是什么?及主要方法有哪些?
本体开发日记02-sparql简单查询
MVCC multi-version concurrency control
软件测试流程包括哪些内容?测试方法有哪些?
“摄像头用不了”+win8.1+DELL+外置摄像头+USB免驱的解决办法
性能测试报告包括哪些内容?模板范文哪里找?看这里
[Personal study summary] CRC verification principle and implementation
随机推荐
unittest测试框架原理及测试流程解析,看完绝对有提升
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
字典
8.Properties property collection
Ontology Development Diary 05-Strive to Understand SWRL (Part 2)
有返回值的函数
How much do you know about the mobile APP testing process specifications and methods?
Go-指针的那些事
你一定要看的安装及卸载测试用例的步骤及方法总结
6.File类
GBase数据库产生迁移工具假死的原因是什么?
unix环境编程学习-多线程
makefile学习-解决目标文件输出路径问题
7.FileFilter接口
Go-接口的那些事
Ontology Development Diary 03 - When debugging is in progress
全网最全的软件测试基础知识整理(新手入门必学)
字符串
类 对象 属性 方法 类的成员
测试用例的原则、缺陷报告怎么写你都知道吗?