Synchronization: Return to the user only after all operations are completed. In this way, the user waits online for too long, giving the user a stuck feeling (that is, when the system is being migrated, if you click Migrate, the interface will not move, but the program is still executing, giving the user a stuck feeling).
In this case, the user cannot close the interface. If closed, the migration process will be interrupted. (Recommended learning: java course)
Asynchronous: Put the user request into the message queue and feed it back to the user. The system migration program has been started. You can close browsing device. Then the program slowly writes to the database. This is asynchronous. But the user does not feel stuck and will tell you that the system has responded to your request. You can close the interface.
The program processes the data, and the B thread modifies the mathematics processed by the A thread.
Obviously this is caused by global resources. Sometimes in order to solve this problem, priority is given to using local variables and secondarily using synchronized code blocks. For such security considerations, system processing must be sacrificed. Performance, the thread synchronization mechanism is implemented where resource competition is most intense when multi-threads are concurrent.
Synchronization: Thread A wants to request a resource, but this resource is being used by thread B. Because the synchronization mechanism exists, thread A cannot reach it. What should I do? Thread A can only wait.
Asynchronous: Thread A wants to request a resource, but this resource is being used by thread B. Because there is no synchronization mechanism, thread A can still request it, and thread A does not need to wait.
3. Summary :
(1) Synchronization is safe, but due to the existence of synchronization mechanism, the performance will be relatively poor
(2) Asynchronous is unsafe and can easily lead to Deadlock, the death of such a thread may cause the entire process to crash; but because there is no synchronization mechanism, multi-threads execute asynchronously, and performance will be improved.
4. A synchronization mechanism is required only if the following requirements are met at the same time:
(1) Multi-threading
(2) There is competition for shared data
The above is the detailed content of The difference between synchronous and asynchronous in java. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor