Skip to content

Commit

Permalink
Issue #64 Refactor project according to IntelliJ inspection suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
simondelabici committed Mar 24, 2020
1 parent a8928e9 commit c785b0b
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -23,12 +24,12 @@ public class LeaderFollowersThreadPool
/**
* Shutdown status flag.
*/
private volatile boolean shutdown = false;
private final AtomicBoolean shutdown = new AtomicBoolean( false );

/**
* Executor.
*/
private ThreadPoolExecutor executor;
private final ThreadPoolExecutor executor;

/**
* Constructor.
Expand All @@ -53,7 +54,7 @@ public LeaderFollowersThreadPool()
// unbounded queue is OK, since its naturally limited (threadPoolSize + # of transports (used for flushing))
executor = new ThreadPoolExecutor (threadPoolSize, threadPoolSize,
Long.MAX_VALUE, TimeUnit.NANOSECONDS,
new LinkedBlockingQueue<Runnable> ());
new LinkedBlockingQueue<> ());
executor.prestartAllCoreThreads ();
}

Expand Down Expand Up @@ -89,18 +90,21 @@ public void execute( Runnable task )
/**
* Shutdown.
*/
public synchronized void shutdown()
public void shutdown()
{
if ( shutdown )
if ( shutdown.get() )
{
return;
shutdown = true;

}
shutdown.set( true );
executor.shutdown ();
try
{
// NOTE: if thead pool is shutdown from one of its threads, this will always block for 1s
if ( !executor.awaitTermination (1, TimeUnit.SECONDS) )
executor.shutdownNow ();
{
executor.shutdownNow();
}
}
catch ( InterruptedException ie )
{ /* noop */ }
Expand Down

0 comments on commit c785b0b

Please sign in to comment.