1. Local code block location: The role of the method: limit the variable life cycle, early release, improve memory utilization. 2. Building code block locations: The same code in multiple construction methods is stored together, executed each time the construct is called,and execute before constructing the method!3. Static code block location: Outside of the method in the class, static modifier: Used to initialize the class, execute at load time, and the value executes once. 4. Synchronizing the code block location: function in the method: Use the Synchronized keyword decoration, and use the "{}" in the enclosed code fragment, it means that only one thread at a time to enter the method block, is a multi-threaded protection mechanism. The format is:
Public void Run () { while (true) { synchronized(obj) { if(tick > 0) { //Try{thread.sleep (40);} catch (Exception e) {} System.out.println (Thread.CurrentThread (). GetName () + "sail--" + tick--) ; } } } }
Java Base _ code block