Through this experiment, we understand the multi-threaded setup and startup, the use of synchronized code blocks, the priority usage of threads, and the knowledge that the classes of resources are thread-shared.
I now understand that multithreading is: instantiating a class that inherits the thread class or implements the Runnable interface (inheritance is to make it eligible to participate in multithreading), and then the code in the class run () is executed by the thread class to enable multi-threaded synchronous operation
After browsing through the web blog, and code to try to further understand the synchronization code block:
The ①synchronized () {} code block is executed to determine whether the object in parentheses is locked:
If none, then lock and start executing code in the code block
If so, enter the blocking queue and wait for the wake-up
When ②synchronized modifies a non-static function, the locked object is this, which is the object that currently references this function.
When ③synchronized modifies a static function, because the static/static method belongs to the class, the current class is locked, and when the static function is accessed, all the threads that want to access the function enter the blocking queue
④synchronized is said to be able to decorate a class,
class ClassName { publicvoid method () { synchronized(ClassName. Class) { // todo } }}
However, the experiment seems to be not mutually exclusive access, should be related to generics, should be in the near future to understand the generic section
Reference from: http://blog.csdn.net/luoweifu/article/details/46613015
2016/9/25 some insights into synchronized (synchronous code block) When compiling Java Experiment Report