封装线程类(MyCopyFileThead.java)
package com.qianyan.sooba.util;
public class MyCopyFileThead {
public static void start(String sourceFile, String targetFile, int blockCount) {
//记录开始时间
long beginTime = System.currentTimeMillis();
//依次分块进行文件COPY
for(int i = 0; i < blockCount; i++){
//实例化文件复制对象
CopyFile copyFile = new CopyFile(sourceFile, targetFile, blockCount, i);
//实例化线程
Thread thread = new Thread(copyFile);
//开始线程
thread.start();
try
{
//加入线程
thread.join();
}
catch (Exception e) {
e.printStackTrace();
}
}
//计算耗时
long endTime = System.currentTimeMillis();
//输出耗时
System.out.println("共用时:" + (endTime - beginTime) + "ms");
}
}