Home> Java> javaTutorial> body text

What is multitasking in java

青灯夜游
Release: 2019-01-30 09:11:32
Original
4352 people have browsed it

In Java, multitasking is the process of executing multiple tasks at the same time; multitasking can be achieved in two ways: multiprocessing and multithreading.

This article will introduce you to multitasking in Java and let you know two ways to implement multitasking. I hope it will be helpful to you. [Related video tutorial recommendations:JavaTutorial]

What is multitasking in java

From the above we know that multitasking is a process of performing multiple tasks at the same time. We can Use multitasking to maximize CPU utilization. Multitasking can be achieved in two ways: multiprocessing and multithreading. Let’s take a closer look at both methods.

Multiprocessing

Multiprocessing is process-based multitasking, it is a process that executes multiple processes at the same time the process of. (Explanation: A process is a running application)

What is multitasking in java

#Multiple processing involves multiple CPUs, and each process has an address in memory. In other words, each process is allocated a separate memory area.

The process of multiprocessing is heavyweight, and the communication cost between the processes is very high; and switching from one process to another takes some time to save and load registers, memory mapping, update lists, etc. .

Multi-threading

Multi-threading is thread-based multi-tasking, it is a process that executes multiple threads at the same time the process of. (Explanation: A thread is a lightweight sub-process and is the smallest processing unit)

The main purpose of multi-threading is to execute two or more parts of the program at the same time to maximize the use of CPU resources. Because threads share the same address space, the communication cost between threads is very low; a multi-threaded program contains two or more parts that can run concurrently.

What is multitasking in java

Why use multithreading instead of multiprocessing?

Multiprocessing and multithreading are both used to achieve multitasking, but why do we use multithreading instead of multiprocessing?

This is because threads use shared memory areas, they do not allocate separate memory areas to save memory, and switching up and down between threads takes less time than processes, and the communication cost between threads is lower .

Advantages of multi-threading:

1) Multi-threading will not block users because the threads are independent; we can perform multiple operations at the same time, so we can save time.

2) Threads are independent, so if an exception occurs in a single thread, it will not affect other threads.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

The above is the detailed content of What is multitasking in java. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!