📄 thread.html
字号:
<TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/lang/Thread.html#yield()">yield</A></B>()</CODE><BR> Causes the currently executing thread object to temporarily pause and allow other threads to execute.</TD></TR></TABLE> <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class java.lang.<A HREF="../../java/lang/Object.html">Object</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../java/lang/Object.html#clone()">clone</A>, <A HREF="../../java/lang/Object.html#equals(java.lang.Object)">equals</A>, <A HREF="../../java/lang/Object.html#finalize()">finalize</A>, <A HREF="../../java/lang/Object.html#getClass()">getClass</A>, <A HREF="../../java/lang/Object.html#hashCode()">hashCode</A>, <A HREF="../../java/lang/Object.html#notify()">notify</A>, <A HREF="../../java/lang/Object.html#notifyAll()">notifyAll</A>, <A HREF="../../java/lang/Object.html#wait()">wait</A>, <A HREF="../../java/lang/Object.html#wait(long)">wait</A>, <A HREF="../../java/lang/Object.html#wait(long, int)">wait</A></CODE></TD></TR></TABLE> <P><!-- ============ FIELD DETAIL =========== --><A NAME="field_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Field Detail</B></FONT></TD></TR></TABLE><A NAME="MIN_PRIORITY"><!-- --></A><H3>MIN_PRIORITY</H3><PRE>public static final int <B>MIN_PRIORITY</B></PRE><DL><DD>The minimum priority that a thread can have.</DL><HR><A NAME="NORM_PRIORITY"><!-- --></A><H3>NORM_PRIORITY</H3><PRE>public static final int <B>NORM_PRIORITY</B></PRE><DL><DD>The default priority that is assigned to a thread.</DL><HR><A NAME="MAX_PRIORITY"><!-- --></A><H3>MAX_PRIORITY</H3><PRE>public static final int <B>MAX_PRIORITY</B></PRE><DL><DD>The maximum priority that a thread can have.</DL><!-- ========= CONSTRUCTOR DETAIL ======== --><A NAME="constructor_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Constructor Detail</B></FONT></TD></TR></TABLE><A NAME="Thread()"><!-- --></A><H3>Thread</H3><PRE>public <B>Thread</B>()</PRE><DL><DD>Allocates a new <code>Thread</code> object. This constructor has the same effect as <code>Thread(null, null,</code> <i>gname</i><code>)</code>, where <b><i>gname</i></b> is a newly generated name. Automatically generated names are of the form <code>"Thread-"+</code><i>n</i>, where <i>n</i> is an integer. <p> Threads created this way must have overridden their <code>run()</code> method to actually do anything. An example illustrating this method being used follows: <p><blockquote><pre> import java.lang.*; class plain01 implements Runnable { String name; plain01() { name = null; } plain01(String s) { name = s; } public void run() { if (name == null) System.out.println("A new thread created"); else System.out.println("A new thread with name " + name + " created"); } } class threadtest01 { public static void main(String args[] ) { int failed = 0 ; <b>Thread t1 = new Thread();</b> if (t1 != null) System.out.println("new Thread() succeed"); else { System.out.println("new Thread() failed"); failed++; } } } </pre></blockquote><DD><DL><DT><B>See Also: </B><DD><A HREF="../../java/lang/Thread.html#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)"><CODE>Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="Thread(java.lang.Runnable)"><!-- --></A><H3>Thread</H3><PRE>public <B>Thread</B>(<A HREF="../../java/lang/Runnable.html">Runnable</A> target)</PRE><DL><DD>Allocates a new <code>Thread</code> object. This constructor has the same effect as <code>Thread(null, target,</code> <i>gname</i><code>)</code>, where <i>gname</i> is a newly generated name. Automatically generated names are of the form <code>"Thread-"+</code><i>n</i>, where <i>n</i> is an integer.<DD><DL><DT><B>Parameters:</B><DD><CODE>target</CODE> - the object whose <code>run</code> method is called.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Thread.html#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)"><CODE>Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="Thread(java.lang.ThreadGroup, java.lang.Runnable)"><!-- --></A><H3>Thread</H3><PRE>public <B>Thread</B>(<A HREF="../../java/lang/ThreadGroup.html">ThreadGroup</A> group, <A HREF="../../java/lang/Runnable.html">Runnable</A> target)</PRE><DL><DD>Allocates a new <code>Thread</code> object. This constructor has the same effect as <code>Thread(group, target,</code> <i>gname</i><code>)</code>, where <i>gname</i> is a newly generated name. Automatically generated names are of the form <code>"Thread-"+</code><i>n</i>, where <i>n</i> is an integer.<DD><DL><DT><B>Parameters:</B><DD><CODE>group</CODE> - the thread group.<DD><CODE>target</CODE> - the object whose <code>run</code> method is called.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if the current thread cannot create a thread in the specified thread group.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Thread.html#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)"><CODE>Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="Thread(java.lang.String)"><!-- --></A><H3>Thread</H3><PRE>public <B>Thread</B>(<A HREF="../../java/lang/String.html">String</A> name)</PRE><DL><DD>Allocates a new <code>Thread</code> object. This constructor has the same effect as <code>Thread(null, null, name)</code>.<DD><DL><DT><B>Parameters:</B><DD><CODE>name</CODE> - the name of the new thread.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Thread.html#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)"><CODE>Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="Thread(java.lang.ThreadGroup, java.lang.String)"><!-- --></A><H3>Thread</H3><PRE>public <B>Thread</B>(<A HREF="../../java/lang/ThreadGroup.html">ThreadGroup</A> group, <A HREF="../../java/lang/String.html">String</A> name)</PRE><DL><DD>Allocates a new <code>Thread</code> object. This constructor has the same effect as <code>Thread(group, null, name)</code><DD><DL><DT><B>Parameters:</B><DD><CODE>group</CODE> - the thread group.<DD><CODE>name</CODE> - the name of the new thread.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if the current thread cannot create a thread in the specified thread group.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Thread.html#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)"><CODE>Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="Thread(java.lang.Runnable, java.lang.String)"><!-- --></A><H3>Thread</H3><PRE>public <B>Thread</B>(<A HREF="../../java/lang/Runnable.html">Runnable</A> target, <A HREF="../../java/lang/String.html">String</A> name)</PRE><DL><DD>Allocates a new <code>Thread</code> object. This constructor has the same effect as <code>Thread(null, target, name)</code>.<DD><DL><DT><B>Parameters:</B><DD><CODE>target</CODE> - the object whose <code>run</code> method is called.<DD><CODE>name</CODE> - the name of the new thread.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Thread.html#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)"><CODE>Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)"><!-- --></A><H3>Thread</H3><PRE>public <B>Thread</B>(<A HREF="../../java/lang/ThreadGroup.html">ThreadGroup</A> group, <A HREF="../../java/lang/Runnable.html">Runnable</A> target, <A HREF="../../java/lang/String.html">String</A> name)</PRE><DL><DD>Allocates a new <code>Thread</code> object so that it has <code>target</code> as its run object, has the specified <code>name</code> as its name, and belongs to the thread group referred to by <code>group</code>. <p> If <code>group</code> is <code>null</code>, the group is set to be the same ThreadGroup as the thread that is creating the new thread. <p>If there is a security manager, its <code>checkAccess</code> method is called with the ThreadGroup as its argument. This may result in a SecurityException. <p> If the <code>target</code> argument is not <code>null</code>, the <code>run</code> method of the <code>target</code> is called when this thread is started. If the target argument is <code>null</code>, this thread's <code>run</code> method is called when this thread is started. <p> 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 <code>setPriority</code> may be used to change the priority to a new value. <p> 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 <code>setDaemon </code> may be used to change whether or not a thread is a daemon.<DD><DL><DT><B>Parameters:</B><DD><CODE>group</CODE> - the thread group.<DD><CODE>target</CODE> - the object whose <code>run</code> method is called.<DD><CODE>name</CODE> - the name of the new thread.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if the current thread cannot create a thread in the specified thread group.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Runnable.html#run()"><CODE>Runnable.run()</CODE></A>, <A HREF="../../java/lang/Thread.html#run()"><CODE>run()</CODE></A>, <A HREF="../../java/lang/Thread.html#setDaemon(boolean)"><CODE>setDaemon(boolean)</CODE></A>, <A HREF="../../java/lang/Thread.html#setPriority(int)"><CODE>setPriority(int)</CODE></A>, <A HREF="../../java/lang/ThreadGroup.html#checkAccess()"><CODE>ThreadGroup.checkAccess()</CODE></A>, <A HREF="../../java/lang/SecurityManager.html#checkAccess(java.lang.Thread)"><CODE>SecurityManager.checkAccess(java.lang.Thread)</CODE></A></DL></DD></DL><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="currentThread()"><!-- --></A><H3>currentThread</H3><PRE>public static <A HREF="../../java/lang/Thread.html">Thread</A> <B>currentThread</B>()</PRE><DL><DD>Returns a reference to the currently executing thread object.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>the currently executing thread.</DL></DD></DL><HR><A NAME="yield()"><!-- --></A><H3>yield</H3><PRE>public static void <B>yield</B>()</PRE><DL><DD>Causes the currently executing thread object to temporarily pause and allow other threads to execute.<DD><DL></DL></DD></DL><HR><A NAME="sleep(long)"><!-- --></A><H3>sleep</H3><PRE>public static void <B>sleep</B>(long millis) throws <A HREF="../../java/lang/InterruptedException.html">InterruptedException</A></PRE><DL><DD>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.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>millis</CODE> - the length of time to sleep in milliseconds.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/InterruptedException.html">InterruptedException</A></CODE> - if another thread has interrupted the current thread. The <i>interrupted status</i> of the current thread is cleared when this exception is thrown.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Object.html#notify()"><CODE>Object.notify()</CODE></A></DL></DD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -