Execution eligibility: Open thread but not executed, waiting for execution to be called qualified for execution. But there is no executive power.
Execution right: The thread being executed is called execution. (with Executive qualification)
Thread safety issues:
When more than one thread is open, a thread may appear that the first statement that just executes a function is jumped, and the next thread starts executing, such as if the first thread just executes the IF statement without executing the statement after the IF, and the second thread starts executing. When the first thread is executed again, the data may have changed. Which leads to security issues.
Synchronization functions and synchronized code blocks are all designed to address thread-safety issues.
Synchronizing code blocks
Thread-safety issues are resolved by synchronizing code blocks. By synchronizing code blocks, when a thread enters a synchronized code block, the thread can enter the synchronized code block only if it finishes executing all of the contents of the synchronization block, during which the thread in the synchronized code block loses execution and other threads that have execution rights cannot enter the synchronized code block.
Resolves thread-safety issues
But reduced efficiency, when a thread in the synchronization code block without the execution of the power of another thread can not perform the function, can only wait to jump the transfer of the code block in the synchronization of the thread to execute, the middle of the waiting time is wasted efficiency.
Synchronization (object) objects are arbitrary as long as it is guaranteed that multiple threads use the same object.
Synchronization functions
A synchronization function is the code that is to be executed encapsulated into a function.
The object behind the synchronization function is this and cannot be changed.
The more you use is the synchronized code block, because the object of the synchronized code block can be changed. A synchronous function can be said to be a shorthand form of a synchronized code block. It fixed the object as this.