diff options
Diffstat (limited to 'src/main/java/org/openslx/filetransfer/util/HashChecker.java')
-rw-r--r-- | src/main/java/org/openslx/filetransfer/util/HashChecker.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/org/openslx/filetransfer/util/HashChecker.java b/src/main/java/org/openslx/filetransfer/util/HashChecker.java index 2c404db..bddf829 100644 --- a/src/main/java/org/openslx/filetransfer/util/HashChecker.java +++ b/src/main/java/org/openslx/filetransfer/util/HashChecker.java @@ -39,9 +39,6 @@ public class HashChecker this.algorithm = algorithm; this.queueCapacity = queueLen; this.queue = new LinkedBlockingQueue<>( queueLen ); - CheckThread thread = new CheckThread( false ); - thread.start(); - threads.add( thread ); } private void threadFailed( CheckThread thread ) @@ -109,6 +106,19 @@ public class HashChecker execCallback( task, HashResult.FAILURE ); return true; } + if ( queue.isEmpty() ) { + CheckThread thread; + try { + thread = new CheckThread( false ); + thread.start(); + threads.add( thread ); + } catch ( NoSuchAlgorithmException e1 ) { + LOGGER.warn( "Cannot spawn hash thread", e1 ); + invalid = true; + execCallback( task, HashResult.FAILURE ); + return true; + } + } if ( queue.remainingCapacity() <= 1 && threads.size() < Runtime.getRuntime().availableProcessors() ) { try { CheckThread thread = new CheckThread( true ); |