Watch 1 Star 1 Fork 0

dreamylost / scala-downloadScala

Join us
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
多线程断点下载Scala的两种实现。「Thread、Actor」 spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

Scala 多线程断点下载

使用

启动 FileDownloadMain.scala(thread) 或 FileDownloadActorMain.scala(actor)

超大文件线程数量较多,需要修改系统最大打开文件数量

ulimit -n 2048

修改application.conf

download {
    # actor重试次数
    retry-times = 10
    # 缓冲区
    buffer-size = 64
    # HTTP超时
    timeout = "10 s"
    file {
        # 线程数或actor数
        thread-count = 10
        # 文件保存地址
        save-path = "/Users/youName/Downloads/scala-download"
        # 默认带下载文件路径
        urls = ["https://downloads.lightbend.com/scala/2.13.2/scala-2.13.2.deb"]
        # 记录下载状态的临时文件,下载成功时自动删除,下载中断时继续下载
        tmp-suffix = ".tmp"
    }
}

目前写入是使用seek,因为写入还是单线程IO所以比较慢。如不需要将下载写入文件,可以考虑引入生产者消费者,通过记录序号,还原数据。

随意画的示意图

Comments ( 0 )

Sign in for post a comment

Scala
1
https://gitee.com/dreamlost/scala-download.git
git@gitee.com:dreamlost/scala-download.git
dreamlost
scala-download
scala-download
master

Help Search