본문 바로가기

학습68

[java] Stack & Heap과 Reference의 개념 YABOONG 님의 자바 메모리 - 스택 & 힙 포스팅과 DZone의 Java Memory Mangement 포스팅을 학습한 내용을 정리한 글입니다. 자바 메모리 관리 자바는 백그라운드에서 garbage collector로 사용되지 않는 객체를 청소하며 메모리 관리를 자동으로 해준다. 그렇지만 언제나 완벽할 수는 없어서, 사용하지 않는 객체가 청소되지 않을 수도 있다. 따라서 최적화를 위해서, 메모리 누수를 해결하기 위해서 자바 메모리가 어떻게 사용되는지 알아야만 한다. 자바의 대략적인 메모리 구조는 그림과 같다. 크게 두 부분의 파트 : stack & heap으로 나누어져 있으며, 실제로 heap의 크기가 stack보다 훨씬 커지게 된다. 1. 값 자체를 가지며 stack memory을 차지하는 pri.. 2020. 6. 28.
[gradle] gradle 5부터 lombok의 설정을 신경써야 한다 오류 상황 //build.gradle dependencies { //Util implementation "org.projectlombok:lombok" } //오류 메세지 error: variable courseRepository not initialized in the default constructor - build.gradle에 implementation으로 lombok 의존성을 추가하고, Intellij 프로젝트에서도 enable annotation processing 옵션을 활성화한 상태 - 그런데 @RequiredArgsConstructor를 선언한 Service에서 default constructor를 사용하게 됨 - 결국 생성자에 필요한 인자인 courseRepository를 주입받지 못하.. 2020. 6. 14.
[spring] 스프링 부트에서 @WebMvcTest 사용하며 RestTemplate 주입받기 오류가 발생한 코드 @RestController @RequestMapping("/api/v1") public class ForecastController { private final ForecastYmlRead forecastYmlRead; private final RestTemplate restTemplate; private final ForecastService forecastService; public ForecastController(RestTemplateBuilder restTemplateBuilder, ForecastService forecastService, ForecastYmlRead forecastYmlRead){ this.restTemplate = restTemplateBuilder.b.. 2020. 6. 11.
[java] 익명 클래스와 람다식 익명 클래스 - 추상클래스를 상속하거나 인터페이스를 구현한, 이름없는 클래스 - 재사용이 필요없는 인스턴스를 생성할 때 사용 사용법 CustomInterface inf = new CustomInteface(){ //인터페이스의 추상 메소드 구현 }; - 상속(구현)하는 추상클래스(인터페이스)의 모든 추상메소드를 구현해야 한다. - 익명 인스턴스에서만 사용할 수 있는 필드와 메소드 선언 가능 - 익명 클래스도 컴파일 성공 시, 클래스파일이 생성된다. 예시 //구현 대상 public interface Person { public void foo(); public void bar(); } public class SampleApplication { public static void main(String[] ar.. 2020. 6. 10.
[spring] 스프링 부트에서 REST Client 이용하기 스프링 REST Client 스프링에서 제공 스프링 부트는 쉽게 사용할 수 있도록 자동설정 제공 주의 : RestTemplate / WebClient 자체를 빈으로 등록 X → RestTemplateBuilder / WebClient.Builder를 빈으로 등록 O 1. RestTemplate Blocking I/O 기반의 Synchronous API RestTemplateAutoConfiguration 프로젝트에 spring-web 모듈이 있다면 RestTemplateBuilder를 빈으로 등록 2. WebClient Non-Blocking I/O 기반의 Asynchronous API WebClientAutoConfiguration 프로젝트에 spring-webflux 모듈이 있다면 WebClient... 2020. 5. 23.