Scala Library: scala.sys.ShutdownHookThread
scala.sys.ShutdownHookThread
class ShutdownHookThread extends ThreadA minimal Thread wrapper to enhance shutdown hooks. It knows how to unregister itself.
- Source
- Version
    - 2.9
 
- Since
    - 2.9
 
Deprecated Value Members From java.lang.Thread
final def stop(arg0: java.lang.Throwable): Unit
- Definition Classes
    - Thread
 
- Annotations
    - @Deprecated @ deprecated
 
- Deprecated
    - (Since version) see corresponding Javadoc for more information.
 
(defined at java.lang.Thread)
Value Members From java.lang.Thread
def clone(): AnyRef
Create a copy of the receiver object.
The default implementation of the clone method is platform dependent.
- returns
    - a copy of the receiver object.
 
- Attributes
    - protected[java.lang]
 
- Definition Classes
    - Thread → AnyRef
 
- Annotations
    - @ throws (…)
 
- Note
    - not specified by SLS as a member of AnyRef
 
(defined at java.lang.Thread)
def getState(): State
- Definition Classes
    - Thread
 
(defined at java.lang.Thread)
def getUncaughtExceptionHandler(): UncaughtExceptionHandler
- Definition Classes
    - Thread
 
(defined at java.lang.Thread)
final def join(arg0: Long): Unit
- Definition Classes
    - Thread
 
- Annotations
    - @ throws (…)
 
(defined at java.lang.Thread)
final def join(arg0: Long, arg1: Int): Unit
- Definition Classes
    - Thread
 
- Annotations
    - @ throws (…)
 
(defined at java.lang.Thread)
def setContextClassLoader(arg0: ClassLoader): Unit
- Definition Classes
    - Thread
 
(defined at java.lang.Thread)
final def setDaemon(arg0: Boolean): Unit
- Definition Classes
    - Thread
 
(defined at java.lang.Thread)
final def setName(arg0: String): Unit
- Definition Classes
    - Thread
 
(defined at java.lang.Thread)
final def setPriority(arg0: Int): Unit
- Definition Classes
    - Thread
 
(defined at java.lang.Thread)
def setUncaughtExceptionHandler(arg0: UncaughtExceptionHandler): Unit
- Definition Classes
    - Thread (defined at java.lang.Thread)
 
Full Source:
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2013, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */
package scala
package sys
/** A minimal Thread wrapper to enhance shutdown hooks.  It knows
 *  how to unregister itself.
 *
 *  @author Paul Phillips
 *  @version 2.9
 *  @since   2.9
 */
class ShutdownHookThread private (name: String) extends Thread(name) {
  def remove() = runtime removeShutdownHook this
}
object ShutdownHookThread {
  private var hookNameCount: Int = 0
  private def hookName(): String = synchronized {
    hookNameCount += 1
    "shutdownHook" + hookNameCount
  }
  /** Creates, names, and registers a shutdown hook to run the
   *  given code.
   */
  def apply(body: => Unit): ShutdownHookThread = {
    val t = new ShutdownHookThread(hookName()) {
      override def run() = body
    }
    runtime addShutdownHook t
    t
  }
}Interested in Scala?
I send out weekly, personalized emails with articles and conference talks.
Subscribe now.