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