Thread synchronization: Multiple threads accessing the same resource at the same time, waiting for resource access to end, wasting time, inefficient
Thread Async: Access other resources while idle waiting while accessing resources, implement multithreading mechanism
Asynchronous processing is, you ask me questions now, I can not answer you, wait for me to take the time to deal with your problem. Synchronization is not the reverse, the synchronization information is processed immediately-until the completion of information processing to return the message handle; asynchronous messages will be processed in the background after a period of time--and return the message handle before the end of processing
Differentiate between synchronous and asynchronous
A process initiates multiple unrelated threads that are related to each other asynchronously.
Synchronization must be executed before other operations can be performed, and asynchronous operation is arbitrary
Advantages and disadvantages of synchronization: Resolves thread security issues. Cons: Every time there is a judgment lock, reducing the efficiency. But between security and efficiency, the first thing to consider is security. The premise of synchronization one, multiple threads to perform the time required synchronization, if it is a single thread does not need synchronization. More than one thread is using the same lock during execution. If it is, it is synchronous. Otherwise, it is not synchronized. Synchronzied (obj) {} The same synchronzied (new Object) {} is not the same lock
Synchronize the code that needs to be synchronized in run (), and do not put it in the synchronization code block if there is no synchronization required for the code.
There are two representations of synchronization:
1, synchronous code block, the code that is synchronized keyword encapsulation is synchronous code block, 2, synchronous function, the function that is modified by the synchronous keyword is the synchronization function.
The synchronization code block can be any object, creating a good one lock object before executing it. So where is the lock on the sync function? The lock of a synchronization function is the object that invokes the synchronization function, which is this.
If the synchronization function is modified by static, then the lock of the synchronization function is the class file object formed in the heap memory in this class. This is not necessarily the object of the class, there must be a byte-code file object for that class alone.
What is thread synchronization and what is thread async? Advantages and disadvantages of synchronization