The concept of multithreading

Source: Internet
Author: User
Tags thread class

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

Related Article

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.