Class NetworkCheckThread

  • All Implemented Interfaces:
    java.lang.Runnable

    public class NetworkCheckThread
    extends java.lang.Thread
    Periodically checks network availability.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static long DEFAULT_NET_CHECK_INTERVAL  
      protected java.util.concurrent.atomic.AtomicBoolean isNetAvailable  
      protected java.util.concurrent.atomic.AtomicLong netChecInterval  
      protected java.util.concurrent.atomic.AtomicBoolean showNetStatus  
      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      NetworkCheckThread​(java.util.concurrent.atomic.AtomicBoolean showNetStatus, java.util.concurrent.atomic.AtomicBoolean isNetAvailable, java.lang.Long interval)
      Constructs a new instance of this class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void run()  
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, toString, yield
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_NET_CHECK_INTERVAL

        protected static final long DEFAULT_NET_CHECK_INTERVAL
        See Also:
        Constant Field Values
      • showNetStatus

        protected java.util.concurrent.atomic.AtomicBoolean showNetStatus
      • isNetAvailable

        protected java.util.concurrent.atomic.AtomicBoolean isNetAvailable
      • netChecInterval

        protected java.util.concurrent.atomic.AtomicLong netChecInterval
    • Constructor Detail

      • NetworkCheckThread

        public NetworkCheckThread​(java.util.concurrent.atomic.AtomicBoolean showNetStatus,
                                  java.util.concurrent.atomic.AtomicBoolean isNetAvailable,
                                  java.lang.Long interval)
        Constructs a new instance of this class. Once started, the thread checks network availability at a specified frequency and stores the result in an atomic variable specified to the constructor. The thread terminates when it's interrupted or when a specified boolean atomic variable has the value false.
        Parameters:
        showNetStatus - a reference to an atomic variable indicating whether the thread should continue running. This variable is tested prior to each network check. The thread terminates when it becomes false.
        isNetAvailable - a reference to an atomic variable in which to write the status of the network check.
        interval - the interval at which to perform the network check, or null if the default interval of one second is to be used.
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread