Java Processes and Threads processes and threads

Source: Internet
Author: User

Processes and Threads

In concurrent programming, there is both basic units of execution: processes and threads. In the Java programming language, concurrent programming are mostly concerned with threads. However, processes is also important.

A computer system normally has many active processes and threads. This is true for even in systems-only has a single execution core, and thus only has one thread actually executing at a NY given moment. Processing time for a single core was shared among processes and threads through an OS feature called time slicing.

It's becoming more and more common for computer systems to having multiple processors or processors with multiple execution Cores. This greatly enhances a system ' s capacity for concurrent execution of processes and threads-but concurrency are possible Even on simple systems, without multiple processors or execution cores.

Processes

A process has a self-contained execution environment. A process generally have a complete, private set of basic run-time resources; In particular, each process have its own memory space.

A process has its own environment and resources to run independently.

Processes is often seen as synonymous with programs or applications. However, what is the user sees as a single application may in fact be a set of cooperating processes. To facilitate communication between processes, most operating systems support Inter Process communication (IPC) r Esources, such as pipes and sockets. IPC is used does just for communication between processes on the same system, but processes on different systems.

A process is often seen as an application, but in fact an application can have a lot of processes, and the process is communicated through the IPC.

Most implementations of the Java Vsan run as a single process. A Java application can create additional processes using a ProcessBuilder object. Multiprocess applications is beyond the scope of this lesson.

Threads

Threads is sometimes called lightweight processes. Both processes and threads provide an execution environment, but creating a new thread requires fewer resources than creat ing a new process.

Threads are often seen as a lightweight process, and both processes and threads have a running environment, but creating a thread requires less resources.

Threads exist within a process-every process has at least one. Threads share the process ' s resources, including memory and open files. This makes to efficient, but potentially problematic, communication.

Threads are dependent on processes, so a process has at least one thread, and the resources of the process are shared between threads, including memory, which is more efficient but has latent problems.

Multithreaded execution is an essential feature of the Java platform. Every application have at least one thread-or several, if you count ' system ' threads that does things like memory managemen T and signal handling. But from the application programmer's point of view, you start with just one thread, called the main thread. This thread had the ability to create additional threads, as we'll demonstrate in the next section.

Multithreaded execution is a fundamental feature of the Java platform's operation.


Java Processes and Threads processes and threads

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.