Index: java/lang/Thread.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Thread.java,v
retrieving revision 1.4
diff -u -b -B -r1.4 Thread.java
--- java/lang/Thread.java 2 Feb 2004 10:29:58 -0000 1.4
+++ java/lang/Thread.java 4 Feb 2004 08:44:37 -0000
@@ -131,11 +131,51 @@
private static int numAnonymousThreadsCreated = 0;
/**
- * Allocate a new Thread object, as if by
- * Thread(null, null, fake name)
, where the fake name
- * is "Thread-" + unique integer.
+ * 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.
+ *
+ * Threads created this way must have overridden their
+ * run()
method to actually do anything. An example
+ * illustrating this method being used follows:
+ *
* - * @see #Thread(ThreadGroup, Runnable, String) + * @see java.lang.Thread#Thread(java.lang.ThreadGroup, + * java.lang.Runnable, java.lang.String) */ public Thread() { @@ -694,8 +734,10 @@ public final synchronized void setName(String name) { checkAccess(); - // Use toString hack to detect null. - name = name.toString(); + // The Class Libraries book says ``threadName cannot be null''. I + // take this to mean NullPointerException. + if (name == null) + throw new NullPointerException(); VMThread t = vmThread; if (t != null) t.setName(name); @@ -899,18 +941,15 @@ } /** - * Return a human-readable String representing this Thread. The format of - * the string is:+ * 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 ; + * + * Thread t1 = new Thread(); + * if (t1 != null) + * System.out.println("new Thread() succeed"); + * else { + * System.out.println("new Thread() failed"); + * failed++; + * } + * } + * } + *
"Thread[" + getName() + ',' + getPriority() + ','
- * + (getThreadGroup() == null ? "" : getThreadGroup().getName())
- + ']'
.
+ * Returns a string representation of this thread, including the
+ * thread's name, priority, and thread group.
*
* @return a human-readable String representing this Thread
*/
public String toString()
{
- return ("Thread[" + name + "," + priority + "," +
- (group == null ? "" : group.getName()) + "]");
+ return ("Thread[" + name + "," + priority + ","
+ + (group == null ? "" : group.getName()) + "]");
}
/**