Java Thread manipulation methods

Source: Internet
Author: User

Get and set the thread name

=================================================//File Name       : thread_demo//------------------------------ ------------------------------------------------///Author          : common//Interface Name: mythread//attribute://Method: Class Mythread_1 Implements runnable{//implements Runnable interface private String name;//public mythread_1 (String name) {//constructor method//super ();//this.name = name;//} @Overridepublic void Run () {//overwrite the Run () method in the Thread class//TODO auto-generated method stub for (int i=0;i<10;i++) {// System.out.println (name+ "Run, i=" +i); System.out.println (Thread.CurrentThread (). GetName () + ", i=" +i);//Remove the name of the current thread}}}//main class//function        : Thread_ Demopublic class Runnable_demo {public static void main (string[] args) {mythread_1 mt1 = new Mythread_1 ();//Instantiate Runnable sub-class pair Like new Thread (MT1). Start ();//The system automatically sets the thread name new thread (MT1, "Thread A"). Start ();//manually set the thread name new thread (MT1, "thread B") automatically. Start (); Manually automatically set the thread name new thread (MT1). Start ();//The system automatically sets the thread name new thread (MT1). Start ();//system automatically sets the thread name}}

Java Thread action method

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.