A preliminary understanding of multithreading in Java

Source: Internet
Author: User

Process: A program that is in progress (literal translation). Thread: A control unit (execution path) in the process that is responsible for executing the program. A process can execute multiple paths, called multithreading.

There must be at least one thread in a process.

Multiple threads are opened to run multi-part code at the same time.

Each thread has its own running content. This content can be called a task that the thread will perform.

Multithreading Benefits: Solves the problem of multiple parts running at the same time.

The disadvantage of multithreading: too many threads back to the reduction of efficiency.

In fact, the implementation of the application is the CPU is doing a quick switch to complete. This switch is random.

When the JVM starts, it starts multiple threads, and at least two threads can parse it out.

1, the thread that executes the main function, the thread's task code is defined in the main function.

2, the thread responsible for garbage collection.

Class Demo extends Object{public void Finalize () {System.out.println ("demo OK");}} Class  threaddemo{public static void Main (string[] args) {new demo (); new demo (); new demo (); System.GC (); System.out.println ("Hello world!");}}

A preliminary understanding of multithreading in Java

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.