mafinlib's People
mafinlib's Issues
WesternImpl missing?
Where is WesternImpl?
Maybe ConcurrentHashMap or Static Initialization is an alternative.
I am not sure if this class is truly useful - see my PM - but as a general comment you could use a ConcurrentHashMap here:
Instead of using a Singleton that maintains a Map to other Singletons you may consider a static initialiser:
https://stackoverflow.com/questions/3635396/pattern-for-lazy-thread-safe-singleton-instantiation-in-java
Check double checked locking / Consider lazy initialiser or static initializer
At
the double checked locking idiom is used. This is broken in this form (since the member is non volatility). To fix it the member (singleton) should be volatility (also note that your singleton is not immutable)!
Background Information on Double Checked Locking
Double Checked Locking was broken in Java 1.4 and fixed in 1.5 (around 2005) using the keyword volatility.
See
https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
and
http://www.angelikalanger.com/Articles/EffectiveJava/41.JMM-DoubleCheck/41.JMM-DoubleCheck.html
Note that Double Checked locking is also broken in C++ and this is fixed in C++ 11 (around 2011), see
http://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/
Improvements
For lazy init I would recommend to use a standard LazyInitializer:
https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/concurrent/LazyInitializer.html
implementing a ConcurrentInitializer:
http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/concurrent/ConcurrentInitializer.html
But for Singlestons lazy initialisation is trivial because you can use a static initializer - note that classed are not loaded until they are needed (Java does Lazy w.r.t. class loading) and a static initalizer is executed upon class loading - and thread safe by spec:
https://stackoverflow.com/questions/3635396/pattern-for-lazy-thread-safe-singleton-instantiation-in-java
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.