Process, thread, multi-thread concept Detailed

Preface

  Recent understanding of the threads feel a very chaotic, so go back and start from scratch combing knowledge thread.

  The current into the road when the encounter a problem, stop and look back on my finishing done in the past, learned, may be able to let you suddenly see the light.

  The following discussion is based on single-core processors.

What processes are?

  The process is running instance, it is the basic unit of resource application program to the operating system (such as memory space).

Open the Windows operating system's task manager, click on the menu you can see the process all the processes existing system.

For example, a word document is a running process. Life will go through the normal process of loading from the code, code execution

A complete process to code execution completed. This process is also generated from the process itself, the process of implementation of the final demise.

If you still feel not well understood, then give an example, and Java-related - console print HelloWord:

public class HelloWorld {
    public static void main(String[] args) {
        
        System.out.println("Hello world.");
        
    }
}

When running (click Run As Java Application) code and they will produce a process to load compiled code,

Then perform tasks print Hello world, after the demise of the implementation is complete.

  The operating system can have a lot of progress, but the same time, only one process run. After the process and does not necessarily produce

Can be executed immediately, running to the need to allocate processor resources (this one is related to the concept of process scheduling, probably do not know you can go to find out ).

What threads are?

  A thread is the smallest executable process units. A thread is further divided carried out on the basis of the process, a process can be only one thread,

It may also contain multiple threads. For example, when using Word, assuming typing is a thread, the thread's task is typing, if there is a spelling

Error, Word will draw the wrong word in red below. So virtually every operating system to start a World is to create a process, and

This process there are many other programs running (such as spell checking), which is a program threads. If Word is closed, these

Spelling checker thread will disappear. On the other hand, spell checking disappear, then Word will not necessarily disappear process.

Why use multithreading?

  Examples of typing or Word, usually use Word, in times of spelling errors, almost at the same spelling error on the show.

Because typing is currently a thread Word process, spell check too. And when we are typing, spell checking are "simultaneously" run,

This has the advantage is that you can quickly know there is a typo, timely manner. If have been written in the document, and then spell checking,

For users will be very bad experience. One of the advantages of this multi-threaded - improve the responsiveness of the system. 

Advantage:

1. improve the system throughput. Example: a site can accept and process multiple requests.
2. improving system responsiveness. For example: while downloading a file can do other operations, but the situation will not have to download is complete before they can do.
3. minimize system resource usage. Multiple threads can share resources processes.

Multiple threads at the same time is really running it?

  The answer is no - not. After the process to get the system allocates processor resources, the scheduler process to choose which program to run,

Process the same time, only one thread running. Just system processing speed is very fast, the feeling is running at the same time visually.

to sum up:

  Learn the most important technical foundation, to understand the concept, it is the key to master multi-threaded programming.

I wanted to process scheduling and thread scheduling a note, but this part of the contents of only vaguely.

This time will be very much like their own in college have a good school "computer operating system," this course.

In computer science, process scheduling and thread scheduling regarded as the foundation.

  Sleight, stole a lazy, all to repay. mutual encouragement.

 

Guess you like

Origin www.cnblogs.com/chaojizhengui/p/javaThread.html