본문 바로가기
728x90
반응형
SMALL

IT279

@Async, @Scheduled, ListenableFuture Exception handling 별도의 Thread 로 동작하는 method 에서 발생하는 예외는 어떻게 처리해야 할까? 적절한 처리가 없을 경우 오류 발생 시 로그조차 기록되지 않아 큰 문제가 될 수 있다. @Async - Async annotation 을 이용할 경우 보통 AsyncConfigurer 를 implements 하여 Thread-pool 을 정의 해 주는 것이 좋다. - AsyncConfigurer 를 implements 할 때 getAsyncUncaughtExceptionHandler 를 Override 하여 작성한다. @Override public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { return (ex, method, params) .. 2022. 3. 28.
Rest API Response 압축하기 (Response size 줄이기) Response size 가 너무 클 때 압축하는 방법은 무엇이 있을까? Json data 라고 가정하고 생각해 보면 1. 가장 간단한건 serializing 할 때 json name:value 에서 name 을 줄이는 것이다. Gson 을 사용한다고 가정하고 @SerializedName 을 사용하면 쉽게 줄일 수 있다. public class UserDto { @SerializedName(value = "x", alternate = "x") protected int no; @SerializedName(value = "i", alternate = "i") protected String id; @SerializedName(value = "n", alternate = "n") protected String .. 2022. 3. 17.
No qualifying bean of type 'org.springframework.core.task.TaskExecutor' available: expected single matching bean but found 2: applicationTaskExecutor, taskScheduler Spring boot 에서 @Async 와 @Scheduled 를 동시에 사용할 때 No qualifying bean of type 'org.springframework.core.task.TaskExecutor' available: expected single matching bean but found 2: applicationTaskExecutor, taskScheduler 이런 로그를 볼 수 있다. @Async 기본설정은 SimpleAsyncTaskExecutor 를 사용하도록 되어 있고 @Scheduled 는 spring 에 의해 생성된 한개의 thread-pool 에서 실행된다. Spring 에서 생성한 thread-pool 과 SimpleAsyncTaskExecutor 모두 'org.spring.. 2022. 3. 2.
Ehcache Event Listener Ehcache 를 사용할 때 cache 가 remove 되는 시점을 알고 싶은 경우가 있다. ehcache v2 (2.10.9.2) 에서 cache 에 대한 event listener 를 통해 확인할 수 있는 방법을 정리 한다. (ehcache v3 에 대해서는 예제 코드가 많은데 v2 에 대해서는 별로 없어서 정리한다.) ehcache 사용하기 "cacheManager" 는 spring cache 에서 같은 이름이 있기 때문에 "ehCacheManager" 로 설정했다. @Configuration public class CacheConfigure { @Bean(name="cacheManagerFactoryBean") public EhCacheManagerFactoryBean ehCacheManagerF.. 2021. 9. 13.
728x90
반응형
LIST