The concept Java threads

And most other computers in different languages, Java support built-in multi-threaded programming (multithreaded programming).

Multi-threaded programs running concurrently section contains two or more than two. Each such program called a thread portion (thread), each thread has its own execution path. Therefore, Multithreading is a specialized form of multitasking.

You must know that multitasking because it is actually supported by all modern operating systems. However, multi-tasking, there are two distinct types: process-based and thread-based. The difference between the two is very important to know.

For many readers, process-based multitasking is a more familiar form. Process (process) is essentially a program execution. Therefore, based on the process (process-based) features multi-tasking is to allow your computer to run two or more programs. For example, process-based multitasking so that when you use a text editor to run Java compiler at the same time. In the process-based multitasking, the program is the smallest unit of code assigned by the scheduler.

Based thread (thread-based) multi-tasking environment, the thread is the smallest unit of execution. This means that a program can perform the functions of two or more tasks simultaneously. For example, a text editor, the text may be formatted while printing. So, multi-process handles the "big picture", and multi-threaded programs deal with the details.

Multithreaded program than multi-process procedures require less overhead. Process is the heavyweight task, you need to assign their own separate address space. Inter-process communication is expensive and limited. Conversion between processes is also need to spend. On the other hand, threads are lightweight players. They share the same address space and share the same process. Inter-thread communication is cheap, conversion between threads is low-cost. When the Java program uses a multi-process-tasking environment, Java programs are not multi-process control, and multi-threaded Java is under control.

Multi-threaded program to help you write efficient maximum utilization of CPU, because idle time is kept to a minimum. This is critical for network interconnection interactive Java runtime environment, because idle time is common. For example, the data transfer rate of the network is much lower than the processing capacity of the computer, read and write speed of the local file system resources is much lower than the processing power of the CPU, of course, much slower than the user can enter the computer. In a traditional single-threaded environment, your program must wait for each of these tasks to the next step after completion - although there are a lot of CPU idle time. Multithreading enables you to obtain and take full advantage of idle time.

If you have programming experience in Windows 98 or Windows 2000 operating such a system, then you are already familiar with multi-threaded. However, Java thread management to make multithreading especially convenient, because many of the details for you is easy to handle.

3. The main thread
4. Create a thread
5. Create a multithreaded
6. The isAlive () and join () is used
7. thread priority
8. Thread Synchronization
9. The inter-thread communication
10. The thread deadlock
11. hung thread, recovery and termination

Guess you like

Origin blog.csdn.net/Javaxuxuexi/article/details/92715245