diff options
Diffstat (limited to 'libjava/java/lang/Thread.java')
-rw-r--r-- | libjava/java/lang/Thread.java | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libjava/java/lang/Thread.java b/libjava/java/lang/Thread.java index 505b99b..bac1afd 100644 --- a/libjava/java/lang/Thread.java +++ b/libjava/java/lang/Thread.java @@ -127,6 +127,12 @@ public class Thread implements Runnable /** The context classloader for this Thread. */ private ClassLoader contextClassLoader; + /** This thread's ID. */ + private final long threadId; + + /** The next thread ID to use. */ + private static long nextThreadId; + /** The default exception handler. */ private static UncaughtExceptionHandler defaultHandler; @@ -354,12 +360,17 @@ public class Thread implements Runnable } else group = g; - + data = null; interrupt_flag = false; alive_flag = false; startable_flag = true; + synchronized (Thread.class) + { + this.threadId = nextThreadId++; + } + if (current != null) { group.checkAccess(); @@ -1027,6 +1038,18 @@ public class Thread implements Runnable return defaultHandler; } + /** + * Returns the unique identifier for this thread. This ID is generated + * on thread creation, and may be re-used on its death. + * + * @return a positive long number representing the thread's ID. + * @since 1.5 + */ + public long getId() + { + return threadId; + } + /** * <p> * This interface is used to handle uncaught exceptions |