Improve Javadoc

This commit is contained in:
baislsl
2018-02-19 22:01:14 +08:00
parent d78434fed8
commit 991ba320a6
30 changed files with 88 additions and 80 deletions

View File

@ -28,18 +28,18 @@ import org.slf4j.LoggerFactory;
/**
* Singleton pattern ensures that the class can have only one existing instance per Java classloader
* instance and provides global access to it.
* <p/>
* <p>
* One of the risks of this pattern is that bugs resulting from setting a singleton up in a
* distributed environment can be tricky to debug, since it will work fine if you debug with a
* single classloader. Additionally, these problems can crop up a while after the implementation of
* a singleton, since they may start out synchronous and only become async with time, so you it may
* not be clear why you are seeing certain changes in behaviour.
* <p/>
* <p>
* There are many ways to implement the Singleton. The first one is the eagerly initialized instance
* in {@link IvoryTower}. Eager initialization implies that the implementation is thread safe. If
* you can afford giving up control of the instantiation moment, then this implementation will suit
* you fine.
* <p/>
* <p>
* The other option to implement eagerly initialized Singleton is enum based Singleton. The example
* is found in {@link EnumIvoryTower}. At first glance the code looks short and simple. However, you
* should be aware of the downsides including committing to implementation strategy, extending the
@ -47,16 +47,16 @@ import org.slf4j.LoggerFactory;
* Overflow:
* http://programmers.stackexchange.com/questions/179386/what-are-the-downsides-of-implementing
* -a-singleton-with-javas-enum
* <p/>
* <p>
* {@link ThreadSafeLazyLoadedIvoryTower} is a Singleton implementation that is initialized on
* demand. The downside is that it is very slow to access since the whole access method is
* synchronized.
* <p/>
* <p>
* Another Singleton implementation that is initialized on demand is found in
* {@link ThreadSafeDoubleCheckLocking}. It is somewhat faster than
* {@link ThreadSafeLazyLoadedIvoryTower} since it doesn't synchronize the whole access method but
* only the method internals on specific conditions.
* <p/>
* <p>
* Yet another way to implement thread safe lazily initialized Singleton can be found in
* {@link InitializingOnDemandHolderIdiom}. However, this implementation requires at least Java 8
* API level to work.

View File

@ -24,9 +24,9 @@ package com.iluwatar.singleton;
/**
* Double check locking
* <p/>
* <p>
* http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
* <p/>
* <p>
* Broken under Java 1.4.
*
* @author mortezaadi@gmail.com