싱글톤패턴1 싱글톤 (Singleton) 패턴 구현 private 생성자와 static 메소드를 이용한 방법 단점 → 멀티 스레드 환경에서 동시에 여러 스레드가 들어왔을때 동시에 new 키워드를 통해 서로 다른 인스턴스를 생성할 수 있다. synchronized 키워드 사용하는 방법 : static 메소드를 synchronized static 메소드로 변경하는 방법 public class Settings { private static Settings instance; private Settings(){ } public static synchronized Settings getInstance(){ if(instance == null){ instance = new Settings(); } return instance; } } 장점 → 동시에 여러 스레드.. 2022. 5. 22. 이전 1 다음