working on it ...

Filters

Explore Public Snippets

Sort by

Found 855 snippets matching: singleton

    public by fabiopagoti modified Apr 17, 2011  185721  0  4  0

    Post: Bomba Relógio-Memória ABAP - Procedural x OO - Versão OO Singleton

    Post: Bomba Relógio-Memória ABAP - Procedural x OO - Versão OO Singleton: ABAP101 - Bomba OO Singleton
    *&---------------------------------------------------------------------*
    *& Report  Z_ABAP101_BOMBA_OO
    *&
    *&---------------------------------------------------------------------*
    *& Esse report tem por finalidade esgotar a memória da sessão usando um
    *& código orientado a objetos com apenas uma instancia
    *&---------------------------------------------------------------------*
    
    REPORT  z_abap101_bomba_oo_singleton.
    
    *----------------------------------------------------------------------*
    *       CLASS lcl_data DEFINITION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS lcl_data DEFINITION.
      PUBLIC SECTION.
        DATA: ci_i_data TYPE TABLE OF string.
    ENDCLASS.                    "lcl_data DEFINITION
    
    *----------------------------------------------------------------------*
    *       CLASS lcl_data IMPLEMENTATION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS lcl_data IMPLEMENTATION.
    ENDCLASS.                    "lcl_data IMPLEMENTATION
    
    START-OF-SELECTION.
    
      TYPES: ty_o_ref_data TYPE REF TO lcl_data.
    
      DATA: o_data_object TYPE ty_o_ref_data.
    
      CREATE OBJECT o_data_object.
    
      WHILE 1 = 1.
        APPEND 'X' TO o_data_object->ci_i_data.
      ENDWHILE.
    
    

    public by MarcoDeMagistris modified Apr 5, 2013  19134  47  6  -1

    Java: How to create a log4j Logger Manager using Singleton

    How to create a log4j Logger Manager using Singleton
    /**
    * LoggerManager class
    * This class implements log4j using Singleton
    */
    import org.apache.log4j.Logger;
    import org.apache.log4j.xml.DOMConfigurator;
    
    public class LoggerManager {
    	public enum LogLevel {DEBUG, INFO, WARNING, ERROR, FATAL};
    	private static LoggerManager obj;
    	private Logger oLog;
    	
    	private LoggerManager(){
    		/*
    		* Config.xml: file path used to configure log4j
    		*/
    		DOMConfigurator.configure("Config.xml");
    	}
    	
    	public LoggerManager(Logger logger) {
    		this();
    		setLogger(logger);
    	}
    
    	private void setLogger(Logger _oLog)
    	{
    		oLog = _oLog;
    	}
    	
    	public static LoggerManager getLogger(){
    		if (obj == null)
    			obj = new LoggerManager(Logger.getLogger(LoggerManager.class));
    		
    		return obj;
    	}
    	
    	public void Log(String _sMsg, LoggerManager.LogLevel _eLogLevel){
    		switch(_eLogLevel){
    			case DEBUG:
    				oLog.debug(_sMsg);
    				break;
    			case INFO:
    				oLog.info(_sMsg);
    				break;
    			case WARNING:
    				oLog.warn(_sMsg);
    				break;
    			case ERROR:
    				oLog.error(_sMsg);
    				break;
    			case FATAL:
    				oLog.fatal(_sMsg);
    				break;
    			default:
    				
    		}
    	}
    }
    
    /**
    * Main class
    * ex. Logger Manager example
    */
    public class Main {
    
    	public static void main(String[] args) {
    		LoggerManager.getLogger().Log("Starting Main", LoggerManager.LogLevel.INFO);
    	}
    
    }

    public by skumjava modified Feb 16, 2016  2581  0  6  1

    Java Singleton Design Pattern using Double checked lock http://singletonjava.blogspot.com

    From Singleton design pattern in Java
    public class Singleton {
     private static volatile Singleton design = null; // volatile is required here
     
     public static Singleton getInstance() {
      if(design == null) { // first check
       synchronized(Singleton.class) { // class level lock
        if(design == null) { // second check
         design = new Singleton();
        }
       }
      }
      return design;
     }
    }                                    

    public by cghersi modified Jan 4, 2013  1977  3  6  1

    singleton class

    Simple singleton implementation for Java
    public class MyClass{
    	static Myclass myclass;
    	
    	static { myclass = new MyClass();}
    	
    	private MyClass(){}
    
    	public static MyClass get() { 
    		return myclass;
    	}
    }

    public by cghersi modified Jan 7, 2013  1543  1  4  0

    singleton in Java

    singleton in Java: singleton
    public class MySingleton {
      private static MySingleton singleton = null;
    
      private MySingleton() {}
    
      public static MySingleton get() {
        if (singleton == null) {
          singleton = new MySingleton();
        }
        return singleton;
      }
    }
    
    

    public by MarcoDeMagistris modified Apr 5, 2013  2467  4  5  0

    My First Snippet: How to create a singleton in C#

    This is the first example of a snippet: - the title represents in few words which is the exact issue the snippet resolves; it can be something like the name of a method; - the description (this field) is an optional field where you can add interesting information regarding the snippet; something like the comment on the head of a method; - the c
    public class MyClass 
    { 
       private static MyClass s_current; 
       private static object s_objSync = new object(); 
    
       private MyClass() {} 
    
       public static MyClass Instance 
       { 
           get 
           { 
               if (s_current == null) 
               { 
                   lock (s_objSync) 
                   { 
                       if (s_current == null) 
                           s_current = new MyClass(); 
                   } 
               } 
               return s_current; 
           } 
       } 
    } 

    public by fabio.nosenzo modified Feb 17, 2013  1684  1  7  0

    Implementation of "singleton" design pattern in java language

    Implementation of "singleton" design pattern in java language
    public class MySingleton {
    static MySingleton _singleton;
    
    static { 
    	//build the object in static block, so this is load only once when the class 		is loaded the first time
    _singleton = new MySingleton();
    }
    
    private MySingleton() {
    	//do initialization here...
    }
    
    public static MySingleton get() { 
    
    return _singleton;
    }
    }

    public by terryc modified Feb 17, 2013  2016  1  5  0

    Design pattern in Java: singleton

    Implementation of singleton design pattern in Java
    public class Singleton {
    	static Singleton _singleton;
    	
    	static { 
    		_singleton = new Singleton();
    	}
    	
    	private Singleton() {
    	}
    
    	/**
    	 * Retrieve the only instance available in this JVM
    	 */
    	public static Singleton get() { 
    		return _singleton;
    	}
    }

    public by IanUnderhill modified May 16, 2017  247  15  3  0

    lazy singleton

    public final class Singleton {
        private static volatile Singleton INSTANCE = null;
    
        private Singleton() {// singleton instance}
    
        /**
         * @return the single instance of the class
         */
        public static Singleton getInstance() {
            if (INSTANCE == null) {
                synchronized(Singleton.class) {
                    if (INSTANCE == null) {
                        INSTANCE = new Singleton();
                    }
                }
            }
            return INSTANCE;
        }
    }                                    

    public by fromano modified Oct 10, 2012  1505  0  6  0

    Objective C Singleton pattern

    Implement singleton pattern in Objective C, the ARC-way.
    + (MyClass*)sharedManager {
    	static dispatch_once_t onceToken;
    	__strong static MyClass *instance = nil;
    	dispatch_once(&onceToken, ^{
    		instance = [[self alloc] init];
    	});
    	return instance;
    }
    • Public Snippets
    • Channels Snippets