Class NamePreservingRunnable

  • All Implemented Interfaces:
    java.lang.Runnable

    public class NamePreservingRunnable
    extends java.lang.Object
    implements java.lang.Runnable
    A Runnable wrapper that preserves the name of the thread after the runnable is complete (for Runnables that change the name of the Thread they use.)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.slf4j.Logger LOGGER  
      private java.lang.String newName
      The runnable name
      private java.lang.Runnable runnable
      The runnable task
    • Constructor Summary

      Constructors 
      Constructor Description
      NamePreservingRunnable​(java.lang.Runnable runnable, java.lang.String newName)
      Creates a new instance of NamePreservingRunnable.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void run()
      Run the runnable after having renamed the current thread's name to the new name.
      private void setName​(java.lang.Thread thread, java.lang.String name)
      Wraps Thread.setName(String) to catch a possible Exceptions such as SecurityException in sandbox environments, such as applets
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • newName

        private final java.lang.String newName
        The runnable name
      • runnable

        private final java.lang.Runnable runnable
        The runnable task
    • Constructor Detail

      • NamePreservingRunnable

        public NamePreservingRunnable​(java.lang.Runnable runnable,
                                      java.lang.String newName)
        Creates a new instance of NamePreservingRunnable.
        Parameters:
        runnable - The underlying runnable
        newName - The runnable's name
    • Method Detail

      • run

        public void run()
        Run the runnable after having renamed the current thread's name to the new name. When the runnable has completed, set back the current thread name back to its origin.
        Specified by:
        run in interface java.lang.Runnable
      • setName

        private void setName​(java.lang.Thread thread,
                             java.lang.String name)
        Wraps Thread.setName(String) to catch a possible Exceptions such as SecurityException in sandbox environments, such as applets