Java gets the object and name of the thread

Source: Internet
Author: User

/* Get Thread object and name (very meaningful)

The original thread has its own default name
thread-number This number starts from 0

Method of Thread Parent class
Static thread CurrentThread (): Gets the current thread object equivalent to this
GetName Get thread Name
*/



Class Text extends Thread
{
private String name;
Text (String name)
{
This.name=name;
Super (name); /* The parent class has methods to define the name of the thread */
}
public void Run ()
{
for (int i=0;i<60;i++)
{
System.out.println (name+ "Run---" +i);
System.one.println (Thread.CurrentThread (). GetName () + "Run---" +i);
}
}
}

Class Threadtext
{
public static void Main (String args[])
{
Text t1=new text ("one");
Text t2=new text ("both");
T1.start ();
T2.start ();
for (int i=0;i<60;i++)
{
System.out.println ("Main Run---" +i);
}
}
}

Java gets the object and name of the thread

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.