Thursday, February 17, 2011

Resolution mechanism for multi-threaded Java

 First, the difference between the application process
process (Process) was originally defined in the Unix and other multi-user, multitasking operating system environment that the application for the environment in memory, the concept of the basic execution unit. The Unix operating system cases, the process is the Unix operating system, basic components of the environment is the basic unit of resource allocation system. Unix operating system, almost all users complete control and resource allocation of work operating system through the control of the application process to achieve .
C, C + +, Java and other languages source code written by the appropriate compiler to compile into an executable file, submitted to the computer processor is running. Then, in a state of the application executable is called process. From a user perspective, the process is an application execution. From the perspective of the operating system kernel, the process represents the operating system allocates memory, CPU time slice and other resources, the basic unit is to provide a running program operating environment. the difference between the application process is the application as a static file stored on the computer system's hard disk and other storage space, and the process is in the dynamic conditions of system maintenance by the operating system resource management entity. multi-tasking environment applications The main features of the process procedures, including:
in the course of the process of memory cells in the initial entry points, and the process has survived the process with separate memory address space;
state lifetime of the process, including creation, in place running, blocking and death, and other types;
from the application process in the course of operating instructions issued to the CPU in different forms, the state of the process can be divided into user mode and kernel mode. in a user mode process running under application instructions, the core state in the application process are running operating system commands.
in the Unix operating system boot process, the system automatically creates a swapper, init and other system processes, for the management of memory resources, and user processes scheduling. In the Unix environment, whether it is a process created by the operating system but also by the application of the process of creating, all have a unique process ID (PID).
Second, the process and the difference between Java threads
in the course of the application there is a memory address of the initial entry points, a program code execution in the implementation process used to identify the end of the process sequence and exit points of the memory address, the process of the implementation process in each time point were The only processor instructions and memory unit address that corresponds to.
Java language-defined thread (Thread) also includes a memory entry point address, one exit point address and the ability to order the implementation of the code sequence. but the process and thread important difference is that threads can not be separately, it must run in the active application process, so you can define within the program's thread is the order of concurrent code  .
Unix operating system and Microsoft Windows operating system support multi-user, multi-process concurrent execution, and Java language support within the application process concurrent execution of multiple execution threads. the significance of multi-threaded application is a logical unit can be concurrently executed. but does not mean multi-threading the number of user processes deep into the light out in the
Java Design Patterns Iterator mode (Figure)
implementation, the operating system is not independent of each thread as a separate process to allocate system resources. the process can Create the child process, child process with parent process has a different executable code and data memory space. and in the process of application is used to represent multiple threads to share data in the memory space, but maintain the execution of each thread stack and independent program execution context (Context).
distinction based on the above, the thread is also called lightweight processes (Light Weight Process, LWP). different tasks between threads to allow collaboration and data exchange, making the computer system resource consumption is very low.
thread needs the support of the operating system, not all types of computer support multithreaded applications. Java programming language to support the threads together with the language runtime environment provides the ability to multi-task concurrent execution. This is like the novel a person in the household chores in the process, the clothes into the washing machine will automatically wash the rice in the rice cooker on and start cooking. and so do the dishes, rice cooked, washed clothes at the same time good.
Note: in applications using multiple threads does not increase the CPU's data processing capabilities. only in the multi-CPU computer or network computing architecture, the Java program into multiple concurrent execution threads, the same start multiple threads running, so that different threads running on different processors, Java virtual machine, in order to improve the efficiency of the application.
In addition, if the application must wait for the network connection or database connections and other data throughput speeds are relatively slow resources, multi-threaded applications is very beneficial. Internet-based applications need to be multi-threaded type, for example, when a large number of clients to support the development of server-side application, the application can create as many thread form to respond to a client connection request, so that each connected user exclusively a client connection thread. so that the user feels the user's own server only for the connection service, thereby reducing the response time of the client server. 

No comments:

Post a Comment