Java Base _ code block

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.