우리는 메모리 누수 문제가 발생하고 있으며 아래 코드가 이유가 될 수 있다고 생각합니다. 우리는 싱글 톤 클래스에 정적 메서드를 가지고 있으며 직접 참조되는 동안 메모리 누수를 일으키는 지 의심 스럽습니다.싱글 톤 스프링 빈에서의 정적 메서드 선언
// This class is wired in spring xml and loaded as spring bean
public class SpringSingletonRestClient{
// instance method to make a web-service call
public ServiceResponse getResponseFromARestService(String RequestParam){.....}
// public static helper bean mapping method, that is used outside this class
// for converting the service response object to different object
public static DomainResponse convertServiceResponseToDomainResponse(ServiceResponse serviceResponse){ //conversion logic.... }
}
}
사용
Class MainClass {
//injected as spring bean
SpringSingletonRestClient client;
public void someMethod(){
ServiceResponse serviceResponse = client.getResponseFromARestService(...);
DomainResponse domainResponse = SpringSingletonRestClient.convertServiceResponseToDomainResponse(serviceResponse);
// use domainResponse object
.......
.......
}
}
난 그냥 의사를 추가하기 때문에 더 설명이 필요한 경우 알려 주시기 바랍니다. 우리는 높은 메모리 사용량을 실행하고 있으며 봄에 의해 초기화 된 클래스에서 선언 된 정적 메서드를 사용하면 가비지 수집이 올바르게 수행되지 않아 메모리 누수가 발생한다고 의심됩니다.
질문 - 정적 메소드가 직접 참조에 의해 사용되고 인스턴스 변수에 의해 사용되지 않더라도 스프링에 의해 시작된 싱글 톤 클래스에서 정적 메소드를 사용하는 것은 좋지 않습니까?
정적 메서드를 사용하면 누수가 발생할 수있는 이유가 표시되지 않지만 클래스가 싱글 톤일 때 결코 수집해서는 안된다고 인정해야합니다 (예상되는 경우) –
예, 내가 뿌리를 잡을 때까지는 잘 모르겠다. –