In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
1. Java compiles once and executes everywhere-cross-platform
2 、 gc
3. The difference between jre and jdk:
Jre (java runtime environment) java runtime environment, including jvm's client, class libraries (rt.jar: commonly used collections, io, math, lang, etc. Are all in the rt.jar package)
Jdk (java development kit) java development tools, including jre (client and server with jvm), compiler (javac), diagnostic tools (jconsole.exe, etc.)
4. Java basic class library: (beginning with java)
Java.lang (wrapper classes such as exception/string/stringbuffer/Integer / math/annotion)
Java.util (concurrent/regex regular expression / collection/ date date calendar)
Reference https://blog.csdn.net/basycia/article/details/50769838
5. Third-party class libraries commonly used in java: (beginning with javax)
Javax.swing 、 javax.naming
6. Cas principle
The classes under the java.util.concurrent package all use cas principles to achieve concurrency, such as automicInteger and concurrentHashMap
Main memory A, thread cache data B, update value C, and C is assigned to An only when BackA is used.
7. Concurrency feature, which can be implemented by syn or lock.
Atomicity
Orderliness: when jvm executes java code, it will rearrange instructions without affecting the running results. Orderliness is to avoid instruction rearrangement.
Memory visible
8. Volatile keyword
Can ensure that the memory is visible: thread A writes the data to the main memory immediately after modification.
Ordering: modified keywords are not rearranged by instructions. Ensure that when performing keyword-related operations, the previous code has been executed and the subsequent code has not been executed, but the sequence of the code before and after the keyword is not guaranteed.
There is no guarantee of atomicity.
A typical application scenario of volatile is singleton mode.
Class Singleton {private volatile static Singleton instance= null; private Singleton () {} public static Singleton getInstance () {if (instance==null) {synchronized (Singleton.class) {if (instance==null) instance= new Singleton ();}} return instance;}}
Why does the singleton pattern need to be modified with volatile?
It mainly lies in the sentence instance = new Singleton (), which is not an atomic operation. In fact, this sentence in JVM does about three things:
1. Allocate memory to instance
two。 Call the constructor of Singleton to initialize member variables
3. Point the instance object to the allocated memory space (instance will be non-null after performing this step).
But there is an optimization for instruction reordering in JVM's just-in-time compiler. In other words, the order of the second and third steps above cannot be guaranteed, and the final execution order may be 1-2-3 or 1-3-2. If it is the latter, it is preempted by thread 2 before the execution of 3 and 2, and the instance is already non-null (but not initialized), so thread 2 will directly return instance, then use it, and then naturally report an error.
Reference:
Do you really know the volatile keyword?
Deep and simple CAS
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy
© 2024 shulou.com SLNews company. All rights reserved.