반응형

상황

kafka 의 jvm 옵션을 보니 Xms 와 Xmx 가 같게 설정되어 있어서 찾아보게 되었다

답변

1. 힙 크기를 늘릴 때 OS 에 추가 메모리를 요청해야 하므로 시간이 걸린다 (GC 가 처리되었던 요청의 응답시간에 추가됨)

2. JVM 은 힙으로 늘린 메모리를 다시 해제하지 않아 결국엔 Xmx 값이 된다

3. 힙 크기를 늘리는 작업은 stop-the-world 이벤트여서 이를 방지할 수 있다 

4. Xms 가 작게 시작하는 경우 GC 가 더 많이 발생하게 됨

5. 일반적으로 다른 앱과 메모리 경쟁을 하지 않는 경우에 이렇게 설정

 

 

https://stackoverflow.com/questions/43651167/is-there-any-advantage-in-setting-xms-and-xmx-to-the-same-value

https://developer.jboss.org/thread/149559

반응형

'java' 카테고리의 다른 글

Using @PageableDefault in webflux  (0) 2022.04.20
[spring boot] jooq query logging / show sql  (0) 2020.08.05
[java] jar 압축 해제  (0) 2020.08.03
[java][test] JSON 같은지 비교  (0) 2020.07.17
[Guava] cache simple example  (0) 2020.06.03
반응형
  • WebFlux Controller에 Paging 적용하려고 하니
@RequiredArgsConstructor
@RestController
public class PlayerController {

    private final MemberRepository memberRepository;

    @GetMapping("/members")
    public List<Member> requestMembers(@PageableDefault(size = 10) Pageable pageable) {
        return memberRepository.findAll(pageable);
    }
}
 
  • 아래와 같이 에러 발생
No primary or default constructor found for interface org.springframework.data.domain.Pageable
  • WebfluxConfig 추가 필요
@Configuration
@ConditionalOnClass(EnableWebFlux.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
public class WebfluxConfig implements WebFluxConfigurer {
    @Override
    public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
        configurer.addCustomResolver(new ReactivePageableHandlerMethodArgumentResolver());
    }
}

 

 

https://stackoverflow.com/questions/50730446/resolving-pageable-in-webflux

 

반응형

'java' 카테고리의 다른 글

[java] JVM 옵션 -Xms 와 -Xmx 를 같게 하는 이유  (0) 2022.05.26
[spring boot] jooq query logging / show sql  (0) 2020.08.05
[java] jar 압축 해제  (0) 2020.08.03
[java][test] JSON 같은지 비교  (0) 2020.07.17
[Guava] cache simple example  (0) 2020.06.03
반응형

상황

jOOQ 에서 실행되는 SQL 을 show, print, logging 해보자

해결법

1. Listener 생성

public class LoggingExecuteListener extends DefaultExecuteListener {

	@Override
	public void executeStart(ExecuteContext ctx) {
		// Create a new DSLContext for logging rendering purposes
		// This DSLContext doesn't need a connection, only the SQLDialect...
		DSLContext create = DSL.using(ctx.dialect(),
				// ... and the flag for pretty-printing
				new Settings().withRenderFormatted(true));
		// If we're executing a query
		if (ctx.query() != null) {
			System.out.println(create.renderInlined(ctx.query()));
		} else if (ctx.routine() != null) {
			// If we're executing a routine
			System.out.println(create.renderInlined(ctx.routine()));
		} else if (ctx.batchQueries() != null) {
			// If we're executing a batch queries
			Arrays.stream(ctx.batchQueries()).forEach(query -> System.out.println(create.renderInlined(query)));
		}
	}
}

2. ListenerProvider Bean 생성

@Bean
public ExecuteListenerProvider executeListenerProvider() {
    return new DefaultExecuteListenerProvider(new LoggingExecuteListener());
}

 

 

출처

https://www.jooq.org/doc/3.13/manual/sql-execution/execute-listeners 

https://www.jooq.org/doc/latest/manual/sql-building/queryparts/pretty-printing/

반응형

'java' 카테고리의 다른 글

[java] JVM 옵션 -Xms 와 -Xmx 를 같게 하는 이유  (0) 2022.05.26
Using @PageableDefault in webflux  (0) 2022.04.20
[java] jar 압축 해제  (0) 2020.08.03
[java][test] JSON 같은지 비교  (0) 2020.07.17
[Guava] cache simple example  (0) 2020.06.03
반응형
반응형
반응형

상황

테스트 코드에서 JSON 끼리 같은 지 확인이 필요할 때

해결

JSONAssert 를 사용해서 테스트 한다

maven

<dependency>
    <groupId>org.skyscreamer</groupId>
    <artifactId>jsonassert</artifactId>
    <version>1.5.0</version>
<scope>test</scope>
</dependency>
@Test
public void jsonTest() throws JSONException {
    String expected = "{\"name\":\"kim\"}";
    String got = "{\"name\":\"lee\"}";
    JSONAssert.assertEquals(expected, got, false);
}

 

반응형
반응형

상황

Redis 처럼 TTL 이 있는 캐시를 어플리케이션 내부에서 만들 수 있을까?

 

해결

// expireAfterWrite 를 통해서 TTL 설정
Cache<String, String> cache = CacheBuilder.newBuilder()
			.expireAfterWrite(5, TimeUnit.MINUTES) 
			.build();

cache.put("key", "value");
String value = cache.getIfPresent("key"); // Nullable

System.out.println(value)

 

반응형
반응형

상황

hibernate update를 할 때, 로그를 보면 모든 필드를 다 update 하도록 나온다.

값이 변경된 필드만 업데이트 할 순 없을까?

 

해결

엔티티에 @DynamicUpdate 사용하면 된다

 

@DynamicUpdate
@Entity
public class Person {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", updatable = false, nullable = false)
	private Long id;

	private String name;
	private int age;
}

반응형

'java' 카테고리의 다른 글

[java][test] JSON 같은지 비교  (0) 2020.07.17
[Guava] cache simple example  (0) 2020.06.03
[spring boot][logback] how to set log path from command line  (0) 2020.03.11
[Java] Date String parsing  (0) 2019.12.18
[Java] Calendar 에 Date 설정하기  (0) 2019.12.18
반응형

문제

로그 경로를 커맨드 라인에서 받아서 설정하고 싶은데

 

해결

command line

$ java -Dmyapp.log.path=/my/log/path ... 

 

logback-spring.xml

 

...

    <property name="LOG_DIR" value="${myapp.log.path}" />


...

 

반응형

'java' 카테고리의 다른 글

[Guava] cache simple example  (0) 2020.06.03
[hibernate] 변화된 필드만 업데이트 - @DynamicUpdate  (0) 2020.03.27
[Java] Date String parsing  (0) 2019.12.18
[Java] Calendar 에 Date 설정하기  (0) 2019.12.18
[jdbc][mysql] warn ssl connection  (0) 2018.11.23
반응형

String 파싱 해서 Date 객체로 

 

String dateFormatString="31/12/2019";  
Date date1=new SimpleDateFormat("dd/MM/yyyy").parse(dateFormatString);

 

 

 

 

 

 

 

반응형
반응형

Date 객체를 Calendar 객체에 설정하기

 

Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);

 

반응형

+ Recent posts