net.sf.uadetector.internal.util
Class ExecutorServices

java.lang.Object
  extended by net.sf.uadetector.internal.util.ExecutorServices

public final class ExecutorServices
extends java.lang.Object

This utility is intended to provide predefined ExecutorServices which runs in background and can be easily shut-downed within shutdownAll() if necessary.

Author:
André Rouél

Field Summary
static long SHUTDOWN_DURATION
          Timeout (in seconds) to shutdown all available executors at the latest
 
Method Summary
static java.util.concurrent.ExecutorService createBackgroundExecutor()
          Creates a single-threaded executor that is registered by this class in order to shut it down later (when it becomes necessary).
static java.util.concurrent.ScheduledExecutorService createScheduler()
          Creates a single-threaded scheduler that is registered by this class in order to shut it down later (when it becomes necessary).
static void shutdown(java.util.concurrent.ExecutorService executorService)
          Shutdowns the given ExecutorService as soon as possible, but not later than the specified default time (which is 5L seconds).
static void shutdown(java.util.concurrent.ExecutorService executorService, long duration, java.util.concurrent.TimeUnit unit)
          Shutdowns the given ExecutorService as soon as possible, but not later than the specified time.
static void shutdownAll()
          Shuts down all registered scheduler and background workers as soon as possible, but at the latest in specified SHUTDOWN_DURATION seconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHUTDOWN_DURATION

public static final long SHUTDOWN_DURATION
Timeout (in seconds) to shutdown all available executors at the latest

See Also:
Constant Field Values
Method Detail

createBackgroundExecutor

public static java.util.concurrent.ExecutorService createBackgroundExecutor()
Creates a single-threaded executor that is registered by this class in order to shut it down later (when it becomes necessary).

Returns:
a new background executor

createScheduler

public static java.util.concurrent.ScheduledExecutorService createScheduler()
Creates a single-threaded scheduler that is registered by this class in order to shut it down later (when it becomes necessary).

Returns:
a new scheduler

shutdown

public static void shutdown(@Nonnull
                            java.util.concurrent.ExecutorService executorService)
Shutdowns the given ExecutorService as soon as possible, but not later than the specified default time (which is 5L seconds).

Parameters:
executorService - executor to stop

shutdown

public static void shutdown(@Nonnull
                            java.util.concurrent.ExecutorService executorService,
                            @Nonnegative
                            long duration,
                            @Nonnull
                            java.util.concurrent.TimeUnit unit)
Shutdowns the given ExecutorService as soon as possible, but not later than the specified time.

Parameters:
executorService - executor to stop
duration - duration as a numerical value
unit - duration unit

shutdownAll

public static void shutdownAll()
Shuts down all registered scheduler and background workers as soon as possible, but at the latest in specified SHUTDOWN_DURATION seconds.



Copyright © 2011-2014. All Rights Reserved.