Thread basics, java multithreading Basics

Source: Internet
Author: User
Tags windows support

Thread basics, java multithreading Basics

Why does Windows support threads?

In early computers, OS had no thread concept. The whole system was running a single thread, and CPU resources were occupied by one thread. You could only process one

Computing tasks, such as processing and printing a single task or some other computing tasks, when a BUG occurs in the task, the program stops responding. The processing method is to restart the machine,

To solve this problem, MicroSoft Windows NT, an operating system based on multithreading technology, has developed. Windows NT is the Windows

OS.

Process: the abstract concept refers to the set of resources to be used by an application.

Thread: virtualization of the CPU. Windows provides a dedicated thread for each process (a dedicated CPU concept abstracted by CPU fragments ).

 

Thread Overhead:

1. Thread Kernel Object

2. Thread environment Block

3. User Module Stack

4. Kernel Mode Stack

5. DDL thread link AND thread separation (Attach AND detach)

  

 Thread usage reasons:

1. responsiveness.

Windows provides its own thread for each process to ensure that the application will not block other applications when an endless loop occurs. In GUI applications, you can hand over some work

A single thread enables the GUI thread to respond to the user sensitively without freezing previous windows programs.

2. Performance

Because each CPU in Windows schedules one thread and multiple CPUs can execute these threads concurrently, fully mobilize the CPU computing capability and concurrent operations can significantly improve applications.

Performance.

 

  Type of CLR threads

1. Foreground thread: Execute the task that the system really wants to execute. For example, if I want to write an article, for example, the thread that handles the writing is the foreground thread.

2. Background threads: non-critical tasks, such as spelling checks performed by the system when writing an article.

using System;using System.Threading;namespace BackGroundTreadTest{    class Program    {        static void Main()        {            Thread t = new Thread(Worker);            t.IsBackground = true;//Change it to a background Thread            t.Start();            Console.WriteLine("Main Thread.....");        }        private static void Worker()        {            Thread.Sleep(10000);            Console.WriteLine("Working....");        }    }}

This section paves the way for Asynchronous Parallel programming as the basic concept of operating system threads.

 

 

 

 

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.