Process
To view a process in Task Manager, the application corresponds to a process
Memory between processes is isolated, inter-process is socket communication through sockets
What is a thread?
------------------------------
Threads are code snippets that execute concurrently during program execution
Threads are capable of sharing memory.
The execution of the thread is performed from top to bottom in order.
Create thread mode One
Inherit thread
-
The Run method in the subclass overlay that stores the code executed by the thread in run
-
The same thread that creates the subclass object is also created.
-
To open a thread by calling the Start method
Thread is the threading class start ()//notification CPU can start executing the purebred
Run ()//thread specifically executes the code snippet.
Thread t=new thread ();
T.start ();
-
Package com.test0516;
-
-
Class MyThread {
-
-
-
-
-
-
public static void Main (string[] args) {
-
MyThread1 t1=new MyThread1 ();
-
T1.start ();
-
System.out.println ("============");
-
New Thread () {
-
public void Run () {
-
System.out.println ("2nd thred");
-
}
-
-
-
}.start ();
-
-
Thread T2=new thread () {
-
-
@Override
-
public void Run () {
-
System.out.println ("2nd thradaaaaaa============");
-
System.out.println (Thread.CurrentThread (). GetName () + "current T2 thread");
-
}
-
-
};
-
T2.start ();
-
System.out.println (T2.getname () + "WY");
-
-
System.out.println (Thread.CurrentThread (). GetName () + "Current thread");
-
}
-
}
-
Class MyThread1 extends thread{
-
public void Run () {
-
System.out.println ("Run ...");
-
}
-
}
Java Foundation Eighth Day Lectures Summary (2)--Multithreading &thread