Java ConcurrentMap getSingleInstance(Class classType)

Here you can find the source of getSingleInstance(Class classType)

Description

get Single Instance

License

Apache License

Declaration

public static <T> T getSingleInstance(Class<T> classType) throws Exception 

Method Source Code


//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License");

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class Main {
    private static ConcurrentMap<Class, Object> instanceMap = new ConcurrentHashMap<Class, Object>();

    public static <T> T getSingleInstance(Class<T> classType) throws Exception {
        T instance = null;//from  w  ww  . j  a  va  2s .  c om
        if (instanceMap.containsKey(classType)) {
            instance = (T) instanceMap.get(classType);
        } else {
            instance = classType.newInstance();
            instanceMap.put(classType, instance);
        }
        return instance;
    }
}

Related

  1. getConcurrentMap(int... size)
  2. getContextPath()
  3. getFilesystem(String id)
  4. getNestedSet(K1 key, ConcurrentMap> set)
  5. getNewLogFactor(String factorName)
  6. getTypeFromKind(String kind)
  7. is(Class clazz, Collection> clazzes, ConcurrentMap, Boolean> cache)
  8. isClassClass(Class clazz)
  9. putIfAbsent(ConcurrentMap map, K key, V value)