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