saker.util Documentation TaskDoc JavaDoc Packages
public class ExceptionThread extends Thread
Thread subclass that is capable of running ThrowingRunnables and store any thrown exceptions to retrieve later.

If the thread throws an exception during its lifetime, it will be caught by this class and stored to be retrieved after it has been joined.

Subclasses can override runImpl() instead of run() to execute their work.

The class will catch all exceptions that occurr in its run method, and will rethrow any exceptions that are not safe to recover from. Safely recoverable exceptions are: StackOverflowError, OutOfMemoryError, LinkageError, ServiceConfigurationError, AssertionError, Exception. Other Throwables and Errors will be thrown from the run() method of the thread. All exceptions are going to be stored for later retrieval nonetheless.

Constructors
public
Allocates a new Thread object.
public
Allocates a new Thread object.
public
Allocates a new Thread object.
public
Allocates a new Thread object.
public
Allocates a new Thread object.
public
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.
public
ExceptionThread(ThreadGroup group, Runnable target, String name, long stackSize)
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group, and has the specified stack size.
public
Allocates a new Thread object.
public
Allocates a new Thread object.
public
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.
public
ExceptionThread(ThreadGroup group, ThrowingRunnable target, String name, long stackSize)
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group, and has the specified stack size.
public
Allocates a new Thread object.
public
Allocates a new Thread object.
Methods
public Throwable
Gets the exception thrown by the thread.
public Throwable
Joins the thread the same way as Thread.join(), and returns any exception that were caught in the thread.
public Throwable
Joins the thread the same way as Thread.join(), and takes any exception that were caught in the thread.
public void
Joins the thread the same way as Thread.join(), and throws any exception that were caught in the thread.
public final void
run()
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
protected void
Runs the thread.
public Throwable
Takes the exception from the thread object.
Documentation included from: Thread
Allocates a new Thread object. This constructor has the same effect as Thread (null, null, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.
public ExceptionThread(Runnable target)
Documentation included from: Thread
Allocates a new Thread object. This constructor has the same effect as Thread (null, target, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.
targetthe object whose run method is invoked when this thread is started. If null, this classes run method does nothing.
public ExceptionThread(Runnable target, String name)
Documentation included from: Thread
Allocates a new Thread object. This constructor has the same effect as Thread (null, target, name).
targetthe object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.
namethe name of the new thread
public ExceptionThread(String name)
Documentation included from: Thread
Allocates a new Thread object. This constructor has the same effect as Thread (null, null, name).
namethe name of the new thread
public ExceptionThread(ThreadGroup group, Runnable target)
Documentation included from: Thread
Allocates a new Thread object. This constructor has the same effect as Thread (group, target, gname) ,where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.
groupthe thread group. If null and there is a security manager, the group is determined by SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.
targetthe object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.
SecurityExceptionif the current thread cannot create a thread in the specified thread group
public ExceptionThread(ThreadGroup group, Runnable target, String name)
Documentation included from: Thread
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.

If there is a security manager, its checkAccess method is invoked with the ThreadGroup as its argument.

In addition, its checkPermission method is invoked with the RuntimePermission("enableContextClassLoaderOverride") permission when invoked directly or indirectly by the constructor of a subclass which overrides the getContextClassLoader or setContextClassLoader methods.

The priority of the newly created thread is set equal to the priority of the thread creating it, that is, the currently running thread. The method setPriority may be used to change the priority to a new value.

The newly created thread is initially marked as being a daemon thread if and only if the thread creating it is currently marked as a daemon thread. The method setDaemon may be used to change whether or not a thread is a daemon.

groupthe thread group. If null and there is a security manager, the group is determined by SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.
targetthe object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.
namethe name of the new thread
SecurityExceptionif the current thread cannot create a thread in the specified thread group or cannot override the context class loader methods.
public ExceptionThread(ThreadGroup group, Runnable target, String name, long stackSize)
Documentation included from: Thread
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group, and has the specified stack size.

This constructor is identical to Thread(ThreadGroup, Runnable, String) with the exception of the fact that it allows the thread stack size to be specified. The stack size is the approximate number of bytes of address space that the virtual machine is to allocate for this thread's stack. The effect of the stackSize parameter, if any, is highly platform dependent.

On some platforms, specifying a higher value for the stackSize parameter may allow a thread to achieve greater recursion depth before throwing a StackOverflowError. Similarly, specifying a lower value may allow a greater number of threads to exist concurrently without throwing an OutOfMemoryError (or other internal error). The details of the relationship between the value of the stackSize parameter and the maximum recursion depth and concurrency level are platform-dependent. On some platforms, the value of the stackSize parameter may have no effect whatsoever.

The virtual machine is free to treat the stackSize parameter as a suggestion. If the specified value is unreasonably low for the platform, the virtual machine may instead use some platform-specific minimum value; if the specified value is unreasonably high, the virtual machine may instead use some platform-specific maximum. Likewise, the virtual machine is free to round the specified value up or down as it sees fit (or to ignore it completely).

Specifying a value of zero for the stackSize parameter will cause this constructor to behave exactly like the Thread(ThreadGroup, Runnable, String) constructor.

Due to the platform-dependent nature of the behavior of this constructor, extreme care should be exercised in its use. The thread stack size necessary to perform a given computation will likely vary from one JRE implementation to another. In light of this variation, careful tuning of the stack size parameter may be required, and the tuning may need to be repeated for each JRE implementation on which an application is to run.

Implementation note: Java platform implementers are encouraged to document their implementation's behavior with respect to the stackSize parameter.

groupthe thread group. If null and there is a security manager, the group is determined by SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.
targetthe object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.
namethe name of the new thread
stackSizethe desired stack size for the new thread, or zero to indicate that this parameter is to be ignored.
SecurityExceptionif the current thread cannot create a thread in the specified thread group
1.4
public ExceptionThread(ThreadGroup group, String name)
Documentation included from: Thread
Allocates a new Thread object. This constructor has the same effect as Thread (group, null, name).
groupthe thread group. If null and there is a security manager, the group is determined by SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.
namethe name of the new thread
SecurityExceptionif the current thread cannot create a thread in the specified thread group
Documentation included from: Thread
Allocates a new Thread object. This constructor has the same effect as Thread (group, target, gname) ,where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.
groupthe thread group. If null and there is a security manager, the group is determined by SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.
targetthe object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.
SecurityExceptionif the current thread cannot create a thread in the specified thread group
Documentation included from: Thread
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.

If there is a security manager, its checkAccess method is invoked with the ThreadGroup as its argument.

In addition, its checkPermission method is invoked with the RuntimePermission("enableContextClassLoaderOverride") permission when invoked directly or indirectly by the constructor of a subclass which overrides the getContextClassLoader or setContextClassLoader methods.

The priority of the newly created thread is set equal to the priority of the thread creating it, that is, the currently running thread. The method setPriority may be used to change the priority to a new value.

The newly created thread is initially marked as being a daemon thread if and only if the thread creating it is currently marked as a daemon thread. The method setDaemon may be used to change whether or not a thread is a daemon.

groupthe thread group. If null and there is a security manager, the group is determined by SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.
targetthe object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.
namethe name of the new thread
SecurityExceptionif the current thread cannot create a thread in the specified thread group or cannot override the context class loader methods.
public ExceptionThread(ThreadGroup group, ThrowingRunnable target, String name, long stackSize)
Documentation included from: Thread
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group, and has the specified stack size.

This constructor is identical to Thread(ThreadGroup, Runnable, String) with the exception of the fact that it allows the thread stack size to be specified. The stack size is the approximate number of bytes of address space that the virtual machine is to allocate for this thread's stack. The effect of the stackSize parameter, if any, is highly platform dependent.

On some platforms, specifying a higher value for the stackSize parameter may allow a thread to achieve greater recursion depth before throwing a StackOverflowError. Similarly, specifying a lower value may allow a greater number of threads to exist concurrently without throwing an OutOfMemoryError (or other internal error). The details of the relationship between the value of the stackSize parameter and the maximum recursion depth and concurrency level are platform-dependent. On some platforms, the value of the stackSize parameter may have no effect whatsoever.

The virtual machine is free to treat the stackSize parameter as a suggestion. If the specified value is unreasonably low for the platform, the virtual machine may instead use some platform-specific minimum value; if the specified value is unreasonably high, the virtual machine may instead use some platform-specific maximum. Likewise, the virtual machine is free to round the specified value up or down as it sees fit (or to ignore it completely).

Specifying a value of zero for the stackSize parameter will cause this constructor to behave exactly like the Thread(ThreadGroup, Runnable, String) constructor.

Due to the platform-dependent nature of the behavior of this constructor, extreme care should be exercised in its use. The thread stack size necessary to perform a given computation will likely vary from one JRE implementation to another. In light of this variation, careful tuning of the stack size parameter may be required, and the tuning may need to be repeated for each JRE implementation on which an application is to run.

Implementation note: Java platform implementers are encouraged to document their implementation's behavior with respect to the stackSize parameter.

groupthe thread group. If null and there is a security manager, the group is determined by SecurityManager.getThreadGroup(). If there is not a security manager or SecurityManager.getThreadGroup() returns null, the group is set to the current thread's thread group.
targetthe object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.
namethe name of the new thread
stackSizethe desired stack size for the new thread, or zero to indicate that this parameter is to be ignored.
SecurityExceptionif the current thread cannot create a thread in the specified thread group
1.4
Documentation included from: Thread
Allocates a new Thread object. This constructor has the same effect as Thread (null, target, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.
targetthe object whose run method is invoked when this thread is started. If null, this classes run method does nothing.
Documentation included from: Thread
Allocates a new Thread object. This constructor has the same effect as Thread (null, target, name).
targetthe object whose run method is invoked when this thread is started. If null, this thread's run method is invoked.
namethe name of the new thread
Gets the exception thrown by the thread.

Callers should make sure that the thread is finished before calling this.

The exception, or null if none was thrown, or the thread hasn't finished yet.
Joins the thread the same way as Thread.join(), and returns any exception that were caught in the thread.
The exception that was thrown by the thread, or null if none.
InterruptedExceptionIf the current thread was interrupted during waiting.
Joins the thread the same way as Thread.join(), and takes any exception that were caught in the thread.
The exception that was thrown by the thread, or null if none.
InterruptedExceptionIf the current thread was interrupted during waiting.
Joins the thread the same way as Thread.join(), and throws any exception that were caught in the thread.
InterruptedExceptionIf the current thread was interrupted during waiting, or an InterruptedException was caught in the thread.
ThrowableIf an exception was caught in the thread. This is usually an Exception or Error subclass.
public final void run()
Overridden from: Thread
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

Subclasses of Thread should override this method.

protected void runImpl() throws Exception
Runs the thread.

Subclasses can override this method instead of run(), and any exception thrown by this method will be stored to retrieve when the thread is joined.

The default implementation calls super.run().

ExceptionIf the thread fails to successfully complete.
Takes the exception from the thread object.

Callers should make sure that the thread is finished before calling this.

This method will check if the thread has thrown an exception, and will atomically exchange it to a null internally. Further calls to getException() or takeException() will return null.

The exception, or null if none was thrown, or the thread hasn't finished yet.