当前位置:网站首页>Multi thread synchronous downloading of network pictures
Multi thread synchronous downloading of network pictures
2022-06-26 05:59:00 【Mr.Rop】
Multi thread synchronous downloading of network pictures
// practice Thread, Realize multi-threaded synchronous downloading of network pictures
public class TestThread2 extends Thread {
private String url; // Network picture address
private String name; // Save network picture file name
// Constructors
public TestThread2(String url, String name) {
this.url = url;
this.name = name;
}
@Override
public void run() {
WebDownLoader webDownLoader = new WebDownLoader();
webDownLoader.downLoader(url,name);
System.out.println(" Downloaded the file named :" + name);
}
public static void main(String[] args) {
TestThread2 t1 = new TestThread2("https://img.alicdn.com/imgextra/i4/6000000001102/O1CN01HJ1Qxo1K0lCQcyutq_!!6000000001102-0-octopus.jpg","1.jpg");
TestThread2 t2 = new TestThread2("https://gtms02.alicdn.com/tps/i2/TB10vPXKpXXXXacXXXXvKyzTVXX-520-280.jpg","2.jpg");
TestThread2 t3 = new TestThread2("https://gtms03.alicdn.com/tps/i3/TB1gXd1JXXXXXapXpXXvKyzTVXX-520-280.jpg","3.jpg");
t1.start();
t2.start();
t3.start();
}
}
// Downloader
class WebDownLoader{
public void downLoader(String url,String name){
try {
FileUtils.copyURLToFile(new URL(url),new File(name));
} catch (IOException e) {
e.printStackTrace();
System.out.println("IO abnormal ,downLoader There is a problem with the method ");
}
}
}
Conclusion : Threads don't have to execute immediately , from CPU To schedule
边栏推荐
- Sql查询时间段内容
- Redis底层数据结构
- SQL server functions
- Func < T, tresult > Commission - learning record
- COW读写复制机制在Linux,Redis ,文件系统中的应用
- Factory method pattern, abstract factory pattern
- pytorch(环境、tensorboard、transforms、torchvision、dataloader)
- 新的征程
- Given two corresponding point sets AB, how to estimate the parameters of the specified transformation matrix R?
- 卷妹带你学jdbc---2天冲刺Day2
猜你喜欢

Spark source code analysis (I): RDD collection data - partition data allocation

On site commissioning - final method of kb4474419 for win7 x64 installation and vs2017 flash back

Gram 矩阵

Vs2022 offline installation package download and activation

Pytorch (environment, tensorboard, transforms, torchvision, dataloader)

Test depends on abstraction and does not depend on concrete

423-二叉树(110. 平衡二叉树、257. 二叉树的所有路径、100. 相同的树、404. 左叶子之和)

How Navicat reuses the current connection information to another computer

家庭记账程序(第一版)

Selective Search for Object Recognition 论文笔记【图片目标分割】
随机推荐
numpy.log
Soft power and hard power in program development
售前分析
Gram matrix
The difference between overload method and override method
【C语言】深度剖析数据在内存中的存储
MySQL-05
Vs2022 offline installation package download and activation
06. talk about the difference and coding between -is and = = again
A new explanation of tcp/ip five layer protocol model
Given two corresponding point sets AB, how to estimate the parameters of the specified transformation matrix R?
tf. nn. top_ k()
Pytorch (network model training)
423- binary tree (110. balanced binary tree, 257. all paths of binary tree, 100. same tree, 404. sum of left leaves)
Record how to modify the control across threads
5分钟包你学会正则表达式
家庭记账程序(第二版 加入了循环)
怎么把平板作为电脑的第二扩展屏幕
适配器模式
【群内问题学期汇总】初学者的部分参考问题