线程数可配置,输出优化
parent
63c8e87e2b
commit
64a827df0b
|
@ -1,5 +1,6 @@
|
|||
url=https://xxx.xxx/dav/
|
||||
account=xxxxx@qq.com
|
||||
password=xxxxxxx
|
||||
threads=8
|
||||
homePath=E:\\data\\test
|
||||
root=test
|
|
@ -10,7 +10,6 @@ import java.sql.SQLException;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Main {
|
||||
|
@ -34,7 +33,7 @@ public class Main {
|
|||
int fromIndex = WebDavConfig.getHomePath().length();
|
||||
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(8);
|
||||
ExecutorService executor = Executors.newFixedThreadPool(WebDavConfig.getThreads());
|
||||
List<String> finalAllSuccessData = allSuccessData;
|
||||
int allFileSize = allFiles.size();
|
||||
|
||||
|
@ -43,6 +42,9 @@ public class Main {
|
|||
int taskId = i;
|
||||
|
||||
executor.submit(() -> {
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
File cur = allFiles.get(taskId);
|
||||
String relativeName = cur.getAbsolutePath().substring(fromIndex).replaceAll("\\\\", "/");
|
||||
String dbName = WebDavConfig.getRoot() + relativeName;
|
||||
|
@ -57,11 +59,14 @@ public class Main {
|
|||
result = new SendResult(200, dbName + " : Ignored");
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
|
||||
|
||||
synchronized (finishCount) {
|
||||
int now = finishCount.getAndIncrement();
|
||||
String str = String.format("[%d/%d] (%3.2f %%) <%d> %s",
|
||||
String str = String.format("[%d/%d] (%3.2f %%) <%d : %.2f s> %s",
|
||||
now + 1, allFileSize, (now + 1) * 100.0f / allFiles.size(),
|
||||
result.getCode(), result.getResult());
|
||||
result.getCode(), (endTime - startTime)/1000.0, result.getResult());
|
||||
int code = result.getCode();
|
||||
if (code == 200 || code == 201) {
|
||||
System.out.println(str);
|
||||
|
|
|
@ -29,6 +29,11 @@ public class WebDavConfig {
|
|||
*/
|
||||
private final static String root;
|
||||
|
||||
/**
|
||||
* 启用线程数量
|
||||
*/
|
||||
private final static Integer threads;
|
||||
|
||||
static {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
|
@ -42,6 +47,7 @@ public class WebDavConfig {
|
|||
password = properties.getProperty("password");
|
||||
homePath = properties.getProperty("homePath");
|
||||
root = properties.getProperty("root");
|
||||
threads = Integer.parseInt(properties.getProperty("threads"));
|
||||
}
|
||||
|
||||
public static String getUrl() {
|
||||
|
@ -63,4 +69,8 @@ public class WebDavConfig {
|
|||
public static String getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public static Integer getThreads() {
|
||||
return threads;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ import top.dreamcenter.webdav.bean.SendResult;
|
|||
import top.dreamcenter.webdav.prop.WebDavConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* WebDav工具
|
||||
|
|
Loading…
Reference in New Issue