Data request: Text data other data
With multiple threads to complete a task, the task is divided into smaller modules, each of which completes its own module.
Threads: a block of program code that completes a task that creates a thread, stops a thread, breaks threads, and so on.
Type: main thread, child thread
Main thread: At the time of application startup, as the process is created, this thread is called the main path. Used to load the resources that the program must use, including class files and other files.
Child threads: In the main thread, in order to not block the main thread, a thread is created to complete the time-consuming task (operation), which is called a child thread.
Thread core classes and interfaces:
1.Thread class
Features: Create threads, start threads, get thread-related information
2.Runnable class
Features: Tasks that can be performed in a thread are not threads, but tasks in threads, also known as thread bodies.
Application of Threads:
Create thread: t= new Thread ();
Startup thread: T.start ();
Middle thread Break: T.interrupt ();
Dormant thread: Thread.Sleep (ms); MS is MS, static member
Tasks for threads: Overriding the Run method in thread, overriding the run () method at creation time
Application of runnable:
1. Implement the Runnable interface class to implement the task function in the run () method
2. When the thread is created, the object of the Runnable implementation class is passed into the thread construction method;
such as: Downloadtask-"Runnable interface
New Thread (New Downloadtask ()). Start ();
The concept of multithreading