@Async 사용하기

목표 @Async을 사용하는 이유를 이해한다. @Async의 사용 방법을 이해한다. @Async란? bean의 메소드에 @Async를 붙이면 별도의 스레드로 메소드가 실행된다. 호출한 쪽에서는 메소드 호출이 완료되기까지 기다리지 않는다. @Async 사용 방법 configuration @Async를 사용하기 위해서는 configuration에 @EnableAsync 를 추가해야된다. @EnableAsync @Configuration class AsyncConfig @EnableAsync의 옵션 annotation: 기본값으로는 @Async를 사용하지만 커스텀 애노테이션을 사요하고 싶을 때 사용할 수 있따. mode: advice의 종류를 나타낸다. PROXY와 AspectJ가 있다. proxyTargetClass: 프록시 모드를 사용할 때만 사용된다. CGLIB과 JDK가 있다. order: AsyncAnnotationBeanPostProcessor가 적용될 순서를 설정한다....

2024-09-15 · 2 min · 344 words

호스트 네임 vs 도메인 네임

도메인 네임: 넓은 의미로는 네트워크 상에서 컴퓨터를 식별하는 호스트명을 가리키며, 좁은 의미에서는 도메인 레지스트리에게서 등록된 이름을 의미한다. 호스트 네임: 네트워크에 연결된 장치들에게 부여되는 각각의 고유한 이름입니다. 우리가 도메인 주소를 생성하고 나면 서비스를 구분하기 위해 별도의 서브 도메인을 사용하기도 합니다. https://velog.io/@minjae-mj/호스트-네임과-도메인-네임

2024-09-15 · 1 min · 40 words

현재 시각 가져오기

CURRENT_TIMESTAMP 를 호출하면된다. SELECT CURRENT_TIMESTAMP AS current_date_time; ----------------------- 2019-02-23 20:02:21.550 (1 row affected) 참고 자료 https://www.sqlservertutorial.net/sql-server-date-functions/sql-server-current_time-function/

2024-09-15 · 1 min · 16 words

해당 문자열이 숫자인지 확인하는 방법

isNaN 함수를 사용하면 숫자가 아닌 경우 true, 아니면 false가 나온다. 참고 자료 https://stackoverflow.com/questions/175739/how-can-i-check-if-a-string-is-a-valid-number

2024-09-15 · 1 min · 13 words

하나의 쿼리에 여러 record 업데이트

목표 쿼리 하나로 여러 record의 값을 서로 다르게 업데이트 한다.(INSERT 문처럼) 방법 SQL에서 따로 제공하는 문법은 없다. CASE 문을 통해 구현해야 된다. UPDATE BANDS SET PERFORMING_COST = CASE BAND_NAME WHEN 'METALLICA' THEN 90000 WHEN 'BTS' THEN 200000 ELSE PERFORMING_COST END WHERE BAND_NAME IN('METALLICA', 'BTS'); 참고 자료 https://www.geeksforgeeks.org/how-to-update-multiple-records-using-one-query-in-sql-server/

2024-09-15 · 1 min · 47 words

필드의 리스트 순서 보장 문제

JPA를 사용하고 있을 때 DB가 리스트의 순서를 계속 유지시켜 줄 것이라고 믿으면 안된다. @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity public class Room { @OneToMany(mappedBy = "room") private final List<User> users = new ArrayList<>(); ... } 이를 해결하기 위해, 유저가 방에 입장하는 시각을 따로 저장하여 그 순서를 보장하는 형태로 구현을 했다.

2024-09-15 · 1 min · 49 words

프로세스 이름에 특정 문자열을 가진 프로세스

pkill -f 'PATTERN' 참고 자료 https://unix.stackexchange.com/questions/316065/how-to-kill-all-process-with-given-name

2024-09-15 · 1 min · 6 words

페이징을 어떻게 표현하면 좋을까

두 가지 방법이 나왔었다. URI 경로: /rooms/pages/1 URI 쿼리: /rooms?page=1 페이지를 리소스로 취급하면 리소스간의 고유한 계층을 유지하기 힘들다는 단점이 있다. 예를들어 1번방으로 요청하려면 rooms/1 이라고 표현하고 싶은데 pages라는 리소스 때문에 불가능해진다. 따라서 페이지는 rooms라는 자원을 필터링하기 위한 하나의 표현이다. 따라서 URI 쿼리 방식을 선택했다. 참고 자료 https://www.baeldung.com/rest-api-pagination-in-spring

2024-09-15 · 1 min · 47 words

파일이름으로 디렉토리인지 확인

import os os.path.isdir(full_filename) 참고 자료 https://wikidocs.net/39

2024-09-15 · 1 min · 6 words

파일의 끝 부분에 개행을 넣어야 되는 이유

UNIX OS들의 호환성을 높여주기 위한 인터페이스 규격인 POSIX에 파일의 끝부분에 개행을 추가하라는 내용이 담겨있다. 참고 자료 https://blog.coderifleman.com/2015/04/04/text-files-end-with-a-newline/ https://velog.io/@doondoony/posix-eol https://minz.dev/19

2024-09-15 · 1 min · 19 words

파일을 통해서 ContentType 찾아오는 법

Java 표준 중에 Files.probeContentType() 메소드를 사용하면 쉽게 확인할 수 있다. @Test public void whenUsingJava7_thenSuccess() { Path path = new File("product.png").toPath(); String mimeType = Files.probeContentType(path); assertEquals(mimeType, "image/png"); } https://www.baeldung.com/java-file-mime-type 파일 이름만으로 유추하는 방법도 있다. String mimeType = URLConnection.guessContentTypeFromName(file.getName()); https://stackoverflow.com/questions/9670040/what-is-the-best-approach-to-identify-a-specific-file-type-in-java

2024-09-15 · 1 min · 38 words

파일 전체 읽기

@Test public void whenReadSmallFileJava7_thenCorrect() throws IOException { String expected_value = "Hello, world!"; Path path = Paths.get("src/test/resources/fileTest.txt"); String read = Files.readAllLines(path).get(0); assertEquals(expected_value, read); } Files를 이용하면 쉽게 파일 전체를 읽을 수 있다. https://www.baeldung.com/reading-file-in-java

2024-09-15 · 1 min · 32 words

파일 이름에서 확장자 분리

splitext 함수를 호출하고 마지막 요소가 확장자가 된다. import os ext = os.path.splitext(full_filename)[-1] 참고 자료 https://wikidocs.net/39

2024-09-15 · 1 min · 15 words

파라미터로 넘어오는 값 확인하기

MyList myList = mock(MyList.class); ArgumentCaptor<String> valueCapture = ArgumentCaptor.forClass(String.class); doNothing().when(myList).add(any(Integer.class), valueCapture.capture()); myList.add(0, "captured"); assertEquals("captured", valueCapture.getValue()); https://www.baeldung.com/mockito-void-methods

2024-09-15 · 1 min · 15 words

파드에 환경 변수로 데이터 넘겨주기

목표 디플로이먼트를 이용해서 파드를 생성할 때, 파드에서 필요한 데이터를 환경 변수로 설정되도록 하여 넘겨주고자 한다. 파드에 넘겨줄 데이터를 클러스터에서 어떻게 관리할지도 고민해본다. ConfigMap 클러스터 내에 기밀이 아닌 데이터를 저장하는 데 사용하는 API 오브젝트다. 파드는 ConfigMap을 환경 변수, 파라미터 볼류의 구성 파일로 사용할 수 있다. 아래와 같이 명령어로 바로 ConfigMap을 만들 수도 있고, yaml 파일을 이요해서 만들 수도 있다. kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm apiVersion: v1 kind: ConfigMap metadata: creationTimestamp: 2022-02-18T19:14:38Z name: special-config namespace: default resourceVersion: "651" uid: dadce046-d673-11e5-8cd0-68f728db1985 data: special....

2024-09-15 · 2 min · 299 words

특정 필드가 없는 도큐먼트 조회 쿼리

목표 특정 필드가 없는 도큐먼트 조회 쿼리 작성법을 이해한다. exists exists 쿼리를 통해서 필드를 존재하는 도큐먼트를 필터링할 수 있다. GET /_search { "query": { "exists": { "field": "user" } } } 아래 예시와 같이 must_not을 통해 필드가 없는 도큐먼트도 조회가 가능하다. GET /_search { "query": { "bool": { "must_not": { "exists": { "field": "your_field" } } } } } 참고 자료 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html https://stackoverflow.com/questions/29357148/how-to-filter-out-fields-that-do-not-exist-in-elastic-search

2024-09-15 · 1 min · 63 words

특정 포트를 사용하고 있는 프로세스 찾기

lsof -i :포트번호 참고 자료 https://sas-study.tistory.com/281

2024-09-15 · 1 min · 6 words

특정 패키지에 있는 클래스들의 빈 생성자 전부 호출하기

1. 특정 패키지에 있는 클래스 가져오기 이전에 학습했던 System Class Loader를 이용하면 특정 패키지에 있는 모든 클래스를 가지고 올 수 있다. private Set<Class<?>> findAllClassesUsingClassLoader(String packageName) { final InputStream stream = ClassLoader.getSystemClassLoader() .getResourceAsStream(packageName.replaceAll("[.]", "/")); final BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(stream))); return reader.lines() .filter(line -> line.endsWith(".class")) .map(line -> getClass(line, packageName)) .collect(Collectors.toSet()); } private Class<?> getClass(String className, String packageName) { final String classPath = packageName + "." + className.substring(0, className.lastIndexOf('.')); try { return Class....

2024-09-15 · 1 min · 201 words

특정 파드 로그 확인하기

목표 특정 파드에 발생하는 로그를 실시간으로 확인한다. 특정 파드가 재시작 되었을 때 이전 인스턴스의 로그를 확인한다. 방법 기본적으로 kubectl logs <파드 id> 로 파드의 로그를 확인할 수 있다. -f 옵션은 follow의 약자로 로그가 스트리밍 되는 옵션이다. kubectl logs -f <파드 id> 에러 등으로 인해 파드가 재시작되었다면, 재시작 원인을 분석하기 위해 이전 인스턴스의 로그를 확인할 필요도 있다. -p: previous의 약자 kubectl logs -p <파드 id> 참고 자료 https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#logs https://stackoverflow.com/questions/39454962/kubectl-logs-continuously https://www.digitalocean.com/community/questions/how-to-check-the-logs-of-running-and-crashed-pods-in-kubernetes

2024-09-15 · 1 min · 69 words

특정 컬럼에 null이 아닌 row의 개수 구하기

sum(case when [session.id](http://session.id/) is null then 0 else 1 end) case 키워드를 이용하면 된다. 참고 자료 https://www.sqlshack.com/working-with-sql-null-values/

2024-09-15 · 1 min · 17 words