From 031d27823cf99fc71ba4764f9accecb7083a3935 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 27 Jun 2018 13:40:51 +0200 Subject: Fix FindBugs complaints --- .../java/org/openslx/filetransfer/util/HashChecker.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/main/java/org/openslx/filetransfer/util/HashChecker.java') 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 ); -- cgit v1.2.3-55-g7522