All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.lang.Thread Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2007 java2script.org and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Zhou Renjian - initial API and implementation
 *******************************************************************************/

package java.lang;

/**
 * @author zhou renjian
 *
 * 2006-5-5
 */
public class Thread implements Runnable
{
	ThreadLocal.ThreadLocalMap inheritableThreadLocals= null;

	public interface UncaughtExceptionHandler
	{
		/**
		 * Method invoked when the given thread terminates due to the
		 * given uncaught exception.
		 * 

Any exception thrown by this method will be ignored by the * Java Virtual Machine. * @param t the thread * @param e the exception */ void uncaughtException(Thread t, Throwable e); } /** * The minimum priority that a thread can have. */ public final static int MIN_PRIORITY= 1; /** * The default priority that is assigned to a thread. */ public final static int NORM_PRIORITY= 5; /** * The maximum priority that a thread can have. */ public final static int MAX_PRIORITY= 10; private static Thread J2S_THREAD= null; /** * Returns a reference to the currently executing thread object. * * @return the currently executing thread. */ public static Thread currentThread() { if (J2S_THREAD == null) { J2S_THREAD= new Thread(); } return J2S_THREAD; } /** * Causes the currently executing thread to sleep (temporarily cease * execution) for the specified number of milliseconds. The thread * does not lose ownership of any monitors. * * @param millis the length of time to sleep in milliseconds. * @exception InterruptedException if another thread has interrupted * the current thread. The interrupted status of the * current thread is cleared when this exception is thrown. * @see java.lang.Object#notify() * * @j2sNative * alert ("Thread.sleep is not implemented in Java2Script!"); */ public static void sleep(long millis) throws InterruptedException { // ; } /* What will be run. */ private Runnable target; private String name; private int priority; public 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. * * @param target the object whose run method is called. * @see java.lang.Thread#Thread(java.lang.ThreadGroup, * java.lang.Runnable, java.lang.String) */ public Thread(Runnable target) { } /** * 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. * * @param group the thread group. * @param target the object whose run method is called. * @exception SecurityException if the current thread cannot create a * thread in the specified thread group. * @see java.lang.Thread#Thread(java.lang.ThreadGroup, * java.lang.Runnable, java.lang.String) */ /** * Allocates a new Thread object. This constructor has * the same effect as Thread(null, null, name). * * @param name the name of the new thread. * @see java.lang.Thread#Thread(java.lang.ThreadGroup, * java.lang.Runnable, java.lang.String) */ public Thread(String name) { } /** * Allocates a new Thread object. This constructor has * the same effect as Thread(group, null, name) * * @param group the thread group. * @param name the name of the new thread. * @exception SecurityException if the current thread cannot create a * thread in the specified thread group. * @see java.lang.Thread#Thread(java.lang.ThreadGroup, * java.lang.Runnable, java.lang.String) */ /** * Allocates a new Thread object. This constructor has * the same effect as Thread(null, target, name). * * @param target the object whose run method is called. * @param name the name of the new thread. * @see java.lang.Thread#Thread(java.lang.ThreadGroup, * java.lang.Runnable, java.lang.String) */ public Thread(Runnable target, String name) { } /** * 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 group is null and there is a * security manager, the group is determined by the security manager's * getThreadGroup method. If group is * null and there is not a security manager, or the * security manager's getThreadGroup method returns * null, the group is set to be the same ThreadGroup * as the thread that is creating the new thread. * *

If there is a security manager, its checkAccess * method is called with the ThreadGroup as its argument. * This may result in a SecurityException. *

* If the target argument is not null, the * run method of the target is called when * this thread is started. If the target argument is * null, this thread's run method is called * when this thread is started. *

* 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. * * @param group the thread group. * @param target the object whose run method is called. * @param name the name of the new thread. * @exception SecurityException if the current thread cannot create a * thread in the specified thread group. * @see java.lang.Runnable#run() * @see java.lang.Thread#run() * @see java.lang.Thread#setDaemon(boolean) * @see java.lang.Thread#setPriority(int) * @see java.lang.ThreadGroup#checkAccess() * @see SecurityManager#checkAccess */ /** * Allocates a new Thread object so that it has * target as its run object, has the specified * name as its name, belongs to the thread group referred to * by group, and has the specified stack size. * *

This constructor is identical to {@link * #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 {@link StackOverflowError}. * Similarly, specifying a lower value may allow a greater number of * threads to exist concurrently without throwing an an {@link * 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. * * @param group the thread group. * @param target the object whose run method is called. * @param name the name of the new thread. * @param stackSize the desired stack size for the new thread, or * zero to indicate that this parameter is to be ignored. * @exception SecurityException if the current thread cannot create a * thread in the specified thread group. */ /** * Initialize a Thread. * * @param g the Thread group * @param target the object whose run() method gets called * @param name the name of the new Thread * @param stackSize the desired stack size for the new thread, or * zero to indicate that this parameter is to be ignored. */ /** * Causes this thread to begin execution; the Java Virtual Machine * calls the run method of this thread. *

* The result is that two threads are running concurrently: the * current thread (which returns from the call to the * start method) and the other thread (which executes its * run method). * * @exception IllegalThreadStateException if the thread was already * started. * @see java.lang.Thread#run() * @see java.lang.Thread#stop() * * @j2sNative * window.setTimeout ((function (runnable) { * return function () { * runnable.run (); * }; * }) (this), 0); */ public synchronized void start() { // ; } /** * 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. * * @see java.lang.Thread#start() * @see java.lang.Thread#stop() * @see java.lang.Thread#Thread(java.lang.ThreadGroup, * java.lang.Runnable, java.lang.String) * @see java.lang.Runnable#run() */ public void run() { if (target != null) { target.run(); } } /** * Changes the priority of this thread. *

* First the checkAccess method of this thread is called * with no arguments. This may result in throwing a * SecurityException. *

* Otherwise, the priority of this thread is set to the smaller of * the specified newPriority and the maximum permitted * priority of the thread's thread group. * * @param newPriority priority to set this thread to * @exception IllegalArgumentException If the priority is not in the * range MIN_PRIORITY to * MAX_PRIORITY. * @exception SecurityException if the current thread cannot modify * this thread. * @see #getPriority * @see java.lang.Thread#checkAccess() * @see java.lang.Thread#getPriority() * @see java.lang.Thread#getThreadGroup() * @see java.lang.Thread#MAX_PRIORITY * @see java.lang.Thread#MIN_PRIORITY * @see java.lang.ThreadGroup#getMaxPriority() */ public final void setPriority(int newPriority) { if (newPriority > MAX_PRIORITY || newPriority < MIN_PRIORITY) { throw new IllegalArgumentException(); } this.priority= newPriority; } /** * Returns this thread's priority. * * @return this thread's priority. * @see #setPriority * @see java.lang.Thread#setPriority(int) */ public final int getPriority() { return priority; } /** * Changes the name of this thread to be equal to the argument * name. *

* First the checkAccess method of this thread is called * with no arguments. This may result in throwing a * SecurityException. * * @param name the new name for this thread. * @exception SecurityException if the current thread cannot modify this * thread. * @see #getName * @see java.lang.Thread#checkAccess() * @see java.lang.Thread#getName() */ public final void setName(String name) { this.name= name; } /** * Returns this thread's name. * * @return this thread's name. * @see #setName * @see java.lang.Thread#setName(java.lang.String) */ public final String getName() { return String.valueOf(name); } /** * Returns the thread group to which this thread belongs. * This method returns null if this thread has died * (been stopped). * * @return this thread's thread group. */ /** * Returns a string representation of this thread, including the * thread's name, priority, and thread group. * * @return a string representation of this thread. */ public String toString() { return hashCode() + ""; } public static boolean interrupted() { return false; } public StackTraceElement[] getStackTrace() { // TODO Auto-generated method stub return null; } public void interrupt() { } public void join(long ms, int ns) { // TODO Auto-generated method stub } public static void sleep(long ms, int ns) { // TODO Auto-generated method stub } public ClassLoader getContextClassLoader() { // TODO Auto-generated method stub return null; } public void setContextClassLoader(ClassLoader last) { // TODO Auto-generated method stub } public static void yield() { // TODO Auto-generated method stub } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy