< prev index next >

src/java.base/share/classes/java/lang/Thread.java

Print this page




1209      * <code>name</code>.
1210      * <p>
1211      * First the <code>checkAccess</code> method of this thread is called
1212      * with no arguments. This may result in throwing a
1213      * <code>SecurityException</code>.
1214      *
1215      * @param      name   the new name for this thread.
1216      * @exception  SecurityException  if the current thread cannot modify this
1217      *               thread.
1218      * @see        #getName
1219      * @see        #checkAccess()
1220      */
1221     public final synchronized void setName(String name) {
1222         checkAccess();
1223         if (name == null) {
1224             throw new NullPointerException("name cannot be null");
1225         }
1226 
1227         this.name = name;
1228         if (threadStatus != 0) {
1229             setNativeName(name);

1230         }
1231     }
1232 
1233     /**
1234      * Returns this thread's name.
1235      *
1236      * @return  this thread's name.
1237      * @see     #setName(String)
1238      */
1239     public final String getName() {
1240         return name;
1241     }
1242 
1243     /**
1244      * Returns the thread group to which this thread belongs.
1245      * This method returns null if this thread has died
1246      * (been stopped).
1247      *
1248      * @return  this thread's thread group.
1249      */


2125     // Hence, the fields are isolated with @Contended.
2126 
2127     /** The current seed for a ThreadLocalRandom */
2128     @jdk.internal.vm.annotation.Contended("tlr")
2129     long threadLocalRandomSeed;
2130 
2131     /** Probe hash value; nonzero if threadLocalRandomSeed initialized */
2132     @jdk.internal.vm.annotation.Contended("tlr")
2133     int threadLocalRandomProbe;
2134 
2135     /** Secondary seed isolated from public ThreadLocalRandom sequence */
2136     @jdk.internal.vm.annotation.Contended("tlr")
2137     int threadLocalRandomSecondarySeed;
2138 
2139     /* Some private helper methods */
2140     private native void setPriority0(int newPriority);
2141     private native void stop0(Object o);
2142     private native void suspend0();
2143     private native void resume0();
2144     private native void interrupt0();
2145     private native void setNativeName(String name);



2146 }


1209      * <code>name</code>.
1210      * <p>
1211      * First the <code>checkAccess</code> method of this thread is called
1212      * with no arguments. This may result in throwing a
1213      * <code>SecurityException</code>.
1214      *
1215      * @param      name   the new name for this thread.
1216      * @exception  SecurityException  if the current thread cannot modify this
1217      *               thread.
1218      * @see        #getName
1219      * @see        #checkAccess()
1220      */
1221     public final synchronized void setName(String name) {
1222         checkAccess();
1223         if (name == null) {
1224             throw new NullPointerException("name cannot be null");
1225         }
1226 
1227         this.name = name;
1228         if (threadStatus != 0) {
1229             // Don't modify JNI-attached threads
1230             setNativeName(name, false);
1231         }
1232     }
1233 
1234     /**
1235      * Returns this thread's name.
1236      *
1237      * @return  this thread's name.
1238      * @see     #setName(String)
1239      */
1240     public final String getName() {
1241         return name;
1242     }
1243 
1244     /**
1245      * Returns the thread group to which this thread belongs.
1246      * This method returns null if this thread has died
1247      * (been stopped).
1248      *
1249      * @return  this thread's thread group.
1250      */


2126     // Hence, the fields are isolated with @Contended.
2127 
2128     /** The current seed for a ThreadLocalRandom */
2129     @jdk.internal.vm.annotation.Contended("tlr")
2130     long threadLocalRandomSeed;
2131 
2132     /** Probe hash value; nonzero if threadLocalRandomSeed initialized */
2133     @jdk.internal.vm.annotation.Contended("tlr")
2134     int threadLocalRandomProbe;
2135 
2136     /** Secondary seed isolated from public ThreadLocalRandom sequence */
2137     @jdk.internal.vm.annotation.Contended("tlr")
2138     int threadLocalRandomSecondarySeed;
2139 
2140     /* Some private helper methods */
2141     private native void setPriority0(int newPriority);
2142     private native void stop0(Object o);
2143     private native void suspend0();
2144     private native void resume0();
2145     private native void interrupt0();
2146 
2147     // May be called directly via JNI or reflection (when permitted) to
2148     // allow JNI-attached threads to set their native name
2149     private native void setNativeName(String name, boolean allowAttachedThread);
2150 }
< prev index next >