싱글톤
싱글톤 패턴을 쓰는 이유
고정된 메모리 영역을 얻으면서 한번의 new로 인스턴스를 사용하기 때문에 메모리 낭비를 방지할 수 있음
또한 싱글톤으로 만들어진 클래스의 인스턴스는 전역 인스턴스이기 때문에 다른 클래스의 인스턴스들이 데이터를 공유하기 쉽다.
public class GetMessageListService {private static GetMessageListService instance = new GetMessageListService();public static GetMessageListService getInstance() {return instance;}private GetMessageListService() {}
생성자를 private로 두고 getInstance안에서만 객체를 생성한 것을 반환 해준다.