Top Description Inners Fields Constructors Methods
io.netty.util

public final Class ThreadDeathWatcher

extends Object
Class Inheritance
Annotations
@Deprecated
Imports
io.netty.util.concurrent.DefaultThreadFactory, io.netty.util.internal.ObjectUtil, .StringUtil, .SystemPropertyUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.security.AccessController, .PrivilegedAction, java.util.ArrayList, .List, .Queue, java.util.concurrent.ConcurrentLinkedQueue, .ThreadFactory, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean

Deprecated

will be removed in the next major release

Checks if a thread is alive periodically and runs a task when a thread dies.

This thread starts a daemon thread to check the state of the threads being watched and to invoke their associated Runnables. When there is no thread to watch (i.e. all threads are dead), the daemon thread will terminate itself, and a new daemon thread will be started again when a new watch is added.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final InternalLogger
private static final Queue<ThreadDeathWatcher.Entry>
private static final AtomicBoolean
pack-priv static final ThreadFactory
private static final ThreadDeathWatcher.Watcher
private static volatile Thread

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if and only if the watcher thread has been terminated
awaitInactivity
(long timeout, TimeUnit unit)

Waits until the thread of this watcher has no threads to watch and terminates itself.

private static void
schedule(Thread thread, Runnable task, boolean isWatch)

public static void
unwatch(Thread thread, Runnable task)

Cancels the task scheduled via watch(Thread, Runnable).

public static void
watch(Thread
the Thread to watch
thread
,
Runnable
the Runnable to run when the thread dies
task
)

Schedules the specified task to run when the specified thread dies.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
private static final InternalLogger logger
pendingEntriesback to summary
private static final Queue<ThreadDeathWatcher.Entry> pendingEntries
startedback to summary
private static final AtomicBoolean started
threadFactoryback to summary
pack-priv static final ThreadFactory threadFactory
watcherback to summary
private static final ThreadDeathWatcher.Watcher watcher
watcherThreadback to summary
private static volatile Thread watcherThread

Constructor Detail

ThreadDeathWatcherback to summary
private ThreadDeathWatcher()

Method Detail

awaitInactivityback to summary
public static boolean awaitInactivity(long timeout, TimeUnit unit) throws InterruptedException

Waits until the thread of this watcher has no threads to watch and terminates itself. Because a new watcher thread will be started again on watch(Thread, Runnable), this operation is only useful when you want to ensure that the watcher thread is terminated after your application is shut down and there's no chance of calling watch(Thread, Runnable) afterwards.

Returns:boolean

true if and only if the watcher thread has been terminated

scheduleback to summary
private static void schedule(Thread thread, Runnable task, boolean isWatch)
unwatchback to summary
public static void unwatch(Thread thread, Runnable task)

Cancels the task scheduled via watch(Thread, Runnable).

watchback to summary
public static void watch(Thread thread, Runnable task)

Schedules the specified task to run when the specified thread dies.

Parameters
thread:Thread

the Thread to watch

task:Runnable

the Runnable to run when the thread dies

Exceptions
IllegalArgumentException:
if the specified thread is not alive
io.netty.util back to summary

private final Class ThreadDeathWatcher.Entry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
pack-priv final Runnable
pack-priv final Thread

Constructor Summary

AccessConstructor and Description
pack-priv
Entry(Thread thread, Runnable task, boolean isWatch)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

isWatchback to summary
pack-priv final boolean isWatch
taskback to summary
pack-priv final Runnable task
threadback to summary
pack-priv final Thread thread

Constructor Detail

Entryback to summary
pack-priv Entry(Thread thread, Runnable task, boolean isWatch)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
io.netty.util back to summary

private final Class ThreadDeathWatcher.Watcher

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
private final List<ThreadDeathWatcher.Entry>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
private void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

watcheesback to summary
private final List<ThreadDeathWatcher.Entry> watchees

Constructor Detail

Watcherback to summary
private Watcher()

Method Detail

fetchWatcheesback to summary
private void fetchWatchees()
notifyWatcheesback to summary
private void notifyWatchees()
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override