Recently I had to implement a controller that transfers files from A to B. There are about 8000 files with a size of 1-2 mb each.
The idea is to get the maximum number of connections / best transmission speed without knowing the host restrictions.
Now, to my question, is ThreadPoolExecutor the best way to implement this behavior, or is there a better way?
//Code simplified //add all files to callables with type Future<Boolean> while (true) { // entry = get the first result that done. if (entry.getValue().get() == Boolean.TRUE) { results.remove(entry.getKey()); if (results.size() > threadPool.getCorePoolSize()) { if (System.currentTimeMillis() >= nextAttempt) resizeThreadPool(+1); } } else { resizeThreadPool(-1); nextAttempt = System.currentTimeMillis() + someTimeinMs; entry.setValue(threadPool.submit(entry.getKey())); } if (results.isEmpty()) return true; }
Edit: the minimum and maximum number of threads are specified as a parameter.
, (/ - , / , ). , / , . , - / , , , , . , , , , .
, , . , :
, , /. /, , ( ). , , , N , N . , , , , . , , , RAM .
Source: https://habr.com/ru/post/1650833/More articles:Make the vertical space limit constant equal to the percentage of screen height - iosNPM engines - package.json #Считайте последовательное появление конкретных одинаковых символов в строке - PHP - phpHow to get the length of the longest sequence with the same characters in a string? - stringHow to format data columns using renderDataTable () in a DT package? - rHow to eliminate dependency for aroma in gradle - androidI really don’t understand what to do {} while the structure is javaHow to check in python that at least one of the default parameters of the specified function is functionGroovy Switch Statement with List of Values - groovyВ чем разница между использованием "@patch.object" и "с patch.object" в Python? - pythonAll Articles