Background

Appendix A - The Thread API

Java Thread Programming
Paul Hyde
  Copyright 1999 Sams Publishing

Instance Methods
The instance methods refer to a specific thread, unlike the static methods that refer to the current thread.
checkAccess()
public final void checkAccess() throws SecurityException
Checks to see if there is a SecurityManager and if it will allow the current thread to access this Thread . It throws a SecurityException if the current thread is denied access. Many other methods of Thread invoke checkAccess() internally.
destroy()
public void destroy()
Destroys the thread without any cleanup. Still not implemented as of JDK 1.2it will throw a NoSuchMethodError if called.
getContextClassLoader()
public ClassLoader getContextClassLoader() throws SecurityException
Returns the context ClassLoader for this thread. SecurityException might be thrown if the current thread is not allowed to access the class loader. Related method: setContextClassLoader() .
getName()
public final String getName()
Returns the name of the thread. Related method: setName() . See Chapter 3 for more information.
getPriority()
public final int getPriority()
Returns the priority of the thread. Related method: setPriority() . Related variables : Thread.MAX_PRIORITY , Thread.MIN_PRIORITY , and Thread.NORM_PRIORITY . See Chapter 6 for more information.
getThreadGroup()
public final ThreadGroup getThreadGroup()
Returns the ThreadGroup to which the thread belongs if the thread is still alive , or null if it has died.
interrupt()
public void interrupt() throws SecurityException
Interrupt this thread by setting its interrupted status to true . This will cause some blocking methods like the wait() method on Object and the sleep method on Thread to throw an InterruptedException . It can throw a SecurityException if the current thread is not permitted to access this thread. Related methods: isInterrupted() , Thread.interrupted() , and Thread.sleep() . See Chapter 5 for more information.
isAlive()
public final native boolean isAlive()
Returns true if this thread is still alive, false otherwise . A thread is considered to be alive from just after it has been started until just after the run() method returns. Related methods: start() , run() , stop() . See Chapter 5 for more information.
isDaemon()
public final boolean isDaemon()
Returns true if this thread is a daemon thread, or false otherwise. A daemon thread continues to run only as long as there is at least one non-daemon thread still running in the VM. Related method: setDaemon() . See Chapter 5 for more information.
isInterrupted()
public boolean isInterrupted()
Returns the interrupted status of this thread and (unlike interrupted() )does not change the status. Related methods: interrupt() , Thread.interrupted() . See Chapter 5 for more information.
join()
public final void join() throws InterruptedException
Causes the current thread to block and wait an unlimited amount of time for this thread to die. It will throw an InterruptedException if interrupted while waiting for this thread to die. Related methods: join(long) , join(long, int) , interrupt() , and isAlive() . See Chapter 8, Inter-thread Communication, for more information.
join(long)
public final synchronized void join(long ms)
        throws InterruptedException
Causes the current thread to block and wait ms milliseconds for this thread to die. It will throw an InterruptedException if interrupted while waiting for this thread to die. Related methods: join() , join(long, int) , interrupt() , and isAlive() . See Chapter 8 for more information.
join(long, int)
public final synchronized void join(long ms, int ns)
        throws InterruptedException
Causes the current thread to block and wait ms milliseconds plus ns nanoseconds for this thread to die. It will throw an InterruptedException if interrupted while waiting for this thread to die. Related methods: join() , join(long) , interrupt() , and isAlive() . See Chapter 8 for more information.
run()
public void run()
If this method was not overridden in a subclass, it does nothing but call the run() method of the Runnable passed to the constructor. If no Runnable was specified, this method returns right away. When this method returns, the thread dies. Related method: start() . See Chapter 4, Implementing Runnable Versus Extending Thread, for more information.
setContextClassLoader(ClassLoader)
public void setContextClassLoader(ClassLoader newLoader)
        throws SecurityException
Specifies a new class loader for this thread. Throws a SecurityException if the current thread is not permitted to modify this thread. Related method: getContextClassLoader() .
setDaemon(boolean)
public final void setDaemon(boolean newStatus)
        throws SecurityException
If newStatus is true , this thread will be a daemon thread and will automatically die when no non-daemon threads are left running in the VM. If newStatus is false , this thread is a normal thread. This method must be called before this thread is started. It throws a SecurityException if the current thread is not permitted to modify this thread. Related method: isDaemon() . See Chapter 5 for more information.
setName(String)
public final void setName(String newName) throws SecurityException
Changes the name of this thread to newName . Throws a SecurityException if the current thread is not permitted to modify this thread. Related method: getName() . See Chapter 3 for more information.
setPriority(int)
public final void setPriority(int newPriority)
        throws SecurityException, IllegalArgumentException
Changes the thread-scheduling priority of this thread to newPriority . If this threads ThreadGroup has a maximum priority set for the group and newPriority exceeds that maximum, newPriority is silently reduced to the groups maximum allowable value. Throws an IllegalArgumentException if newPriority is not at least Thread.MIN_PRIORITY or if greater than Thread.MAX_PRIORITY . Throws a SecurityException if the current thread is not permitted to modify this thread. Related method: getPriority() . Related methods on ThreadGroup are setMaxPriority() and getMaxPriority() . See Chapter 6 for more information.
start()
public native synchronized void start()
        throws IllegalThreadStateException
Causes the VM to spawn a new thread that begins execution by calling run() ; start() immediately returns. Throws IllegalThreadStateException (subclass of RuntimeException ) if the thread has already been started. Related methods: run() , isAlive() , and stop() . See Chapter 3 for more information.
toString()
public String toString()
Returns a string representation of the current state of this thread including its name, priority, and thread group.

Toc


Java Thread Programming
Java Thread Programming
ISBN: 0672315858
EAN: 2147483647
Year: 2005
Pages: 149
Authors: Paul Hyde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net