Java Threading Application Thread

Source: Internet
Author: User

Java Threading Learning:

Basic concepts:

When a program is opened, a process is started, the thread is opened in the process, and if there is only one thread, the thread is called the main path. If the process stops, it kills the thread before exiting!

Java Threading class: Thread
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6F/62/wKiom1WahB7BIfLkAAEEbMlxEcM761.jpg "title=" Thread detailed figure "alt=" wkiom1wahb7biflkaaeebmlxecm761.jpg "/>

The role of the method:

For example, the start () method enables the thread and invokes the Run method to start the process.

Defines the thread class name;

Class Demo extends Thread

{

The Run method of the carbon runnable;

public void Run ()

{

for (int x=0;x<60;x++)

{

SYSTEM.OUT.PRINTLN ("Thread Start" +x);

}

}

}




Defining the main function class name

Class Threaddemo

{

public static void Main (string[] args)

{

Define the demo class object;

Demo d = new demo ();

Demo D1 = new Demo ();

Call the Start method of the runnable startup thread;

D.start ();

D1.start ();

for (int x=0;x<60;x++)

{

System.out.println ("Hello thread!" +X);

}

}

}


The thread has a default name number, which starts at 0;

Get through the GetName () method

Class Test extends Thread

{

private String name;

Test (String name)

{

This.name=name;

Super (name);

}

public void Run ()

{

for (int x=0;x<50;x++)

{

System.out.println (this. GetName ()+ "..... Run Thread ... "+x");

}

}

}




Class ThreadTest

{

public static void Main (string[] args)

{

Test T1 = new Test ("hhhhh");

Test t2 = new Test ("XXX");

T1.start ();

T2.start ();

}

}



Sleep (Time Custom) method: Pauses execution when a thread encounters the method, and waits for it to complete before executing.

Wait () method

Stop () method

This article is from the "Flying Scorpion" blog, please be sure to keep this source http://tanglongwei.blog.51cto.com/4411684/1671461

Java Threading Application 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.