Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TraceApplicationContext {
- private volatile static TraceApplicationContext instance = new TraceApplicationContext();
- private TraceApplicationContext() {
- }
- public static TraceApplicationContext getInstance() {
- return instance;
- }
- }
- public class SpoutA extends BaseRichSpout {
- public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
- TraceApplicationContext.getInstance().init();
- }
- }
- public class BoltA extends BaseRichBolt {
- private static JedisCluster jedisCluster = TraceApplicationContext.getInstance().getJedisCluster();
- }
- public class BoltB extends BaseRichBolt {
- private static JedisCluster jedisCluster = TraceApplicationContext.getInstance().getJedisCluster();
- }
- public class MySingleton {
- private static MySingleton instance;
- private MySingleton() { ... }
- public static MySingleton getInstance() {
- if (instance == null) { instance = new MySingleton() }
- return instance;
- }
- }
- public enum MySingleton {
- INSTANCE;
- private MySingleton() {...}
- }
- public class MySingleton {
- private static volatile MySingleton instance;
- private MySingleton() { ... }
- public static MySingleton getInstance() {
- if (instance == null) {
- synchronized(MySingleton.class) {
- if (instance == null) {
- instance = new MySingleton();
- }
- }
- }
- return instance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement