A simple program to get the current thread in JAVA environment.
Here we make and object of class Thread and make use of “ getId() “ and “ getName
()“ methods.
Snipet
package
wCodes;
public
class GetCurrentThread
{
public static void main(String[] args)
{
Thread t=Thread.currentThread();
t.setName("Main Thread");
System.out.println("Id of current
thread: "+t.getId());
System.out.println("Name of
current thread: "+t.getName());
System.out.println("Priority of
current thread:"+t.getPriority());
}
}
Output
0 comments :
Post a Comment