전체 글

전체 글

    [Spring] application.yml의 Profile에 대한 테스트 이것저것

    application.yml의 Profile에 대한 테스트 이것저것 Profile에 대한 개념이 있다는 가정하에 진행하겠다. 모른다면 !링크를 참고하자. application-{프로파일}.yml 은 특정 Profile에 맞는 yml 파일이다. Profile을 따로 지정하지 않고 실행하게 된다면 application.yml이 실행이 된다. 그렇다면 이때의 Profile은 무엇으로 실행되는 것일까?? Baeldung 싸이트 피셜로 'default' Profile 이라고 한다. 그렇다면 Profile을 지정하지 않고 돌렸는데 application.yml 이 없다면 어떻게 될까?? //application.yml person: name: defaultBepoz age: 100 //applicati..

    [Java] Atomic, Volatile, Synchronized 에 대해

    Atomic, Volatile, Synchronized 에 대해 멀티 쓰레드의 경우에 공유하는 필드에 대해서 thread-safe를 보장해주어야 한다. public static int idx = 0; 이런식으로 두는 것은 thread-safe 하지않다. Atomic, Volatile, Synchronized 에 대해 알아보자. public class CounterBasic { private static int idx = 0; public static int increase() { return idx++; } public static int idx() { return idx; } } public class CounterSynchronized { private static int idx = 0; public..

    [JPA] JPA CascadeType.PERSIST 에 대한 개인적인 궁금증 해결

    JPA CascadeType.PERSIST 에 대한 개인적인 궁금증 해결 Team과 Member와 같은 1:n의 연관관계를 처리할 때에 Team에 Member를 넣은 후 일일이 Member를 영속화하기 번거로우니 Team만 영속화시켜도 Member 또한 영속화되도록 하기위해 설정을 해준다. 이렇듯이 보통 1에서 n에 대하여 이 속성을 걸어주게된다. @Entity @Getter @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Team { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; @OneToMany(ma..

    [Java] Reflection 사용법 정리

    Reflection 사용법 정리 클래스 객체 검색 Object.getClass(); class Bepoz { int value; public Bepoz(int value) { this.value = value; } } Bepoz bepoz = new Bepoz(10); Class aClass1 = Class.forName("reflection.Bepoz"); //Bepoz 클래스는 reflection 패키지 내부에 있음 기본 유형 래퍼의 TYPE 필드 Class type = Double.TYPE; Class type1 = Integer.TYPE; Class type2 = Void.TYPE; 클래스를 반환하는 메서드 public class Bepoz extends Parent { int value; pub..

    [Java] ExecutorService 와 ThreadPoolExecutor 에 대해

    ExecutorService 와 ThreadPoolExecutor 에 대해 ExecutorService service = Executors.newFixedThreadPool(50); 위 코드가 뜻하는 것은 무엇일까? Executors 는 Executor, ExecutorService, ScheduledExecutorService, ThreadFactory 등을 위한 정적 팩토리 메서드를 지원해주는 클래스다. 내부 메서드를 확인해보면 다음과 같은 팩토리 메서드가 눈에 들어올 것이다. Executors.newSingleThreadExecutor(); Executors.newFixedThreadPool(); Executors.newCachedThreadPool(); Executors.newWorkStealin..

    [Java] CountDownLatch, Semaphore, CyclicBarrier 에 대해

    CountDownLatch, Semaphore, CyclicBarrier 에 대해 CountDownLatch, Semaphore, CyclicBarrier는 자바에서 제공해주는 동기화 클래스이다. 이 클래스들을 이용해서 멀티 스레드와 관련된 코드들을 핸들링 할 수가 있다. CountDownLatch @Test void countDownLatchTest() throws InterruptedException { int numberOfThreads = 10; CountDownLatch latch = new CountDownLatch(10); ExecutorService service = Executors.newFixedThreadPool(numberOfThreads); for (int i = 0; i < nu..

    [Java] OutputStream, InputStream, File 간단 사용법 정리

    OutputStream, InputStream, File 간단 사용법 정리 어느 한쪽에서 다른 쪽으로 데이터를 전달하기 위해서는 두 대상을 연결하고 데이터를 전송할 수 있는 통로가 필요한데 이것을 스트림이라고 생각하면 된다. 스트림은 단방향통신만 가능하므로 입력과 출력을 위한 스트림이 각각 존재해야한다. 입력 스트림이 InputStream, 출력 스트림이 OutputStream이다. 스트림은 FIFO 다. OutputStream OutputStream은 다른 매체에 바이트로 데이터를 쓸 때 사용한다. 데이터를 쓰기위해 write(int a) 메서드를 이용한다. @Test void OutputStream은_데이터를_바이트로_처리한다() throws Exception { byte[] bytes = {110,..

    알고리즘 모아보기

    알고리즘 모아보기 최대공약수 GCD(Grateast Common Divisor) // 재귀 public long gcd(int w, int h) { if (h == 0) { return w; } return gcd(h, w % h); } // 반복문 public static long gcd2(int w, int h) { int n; if (w < h) { int temp = w; w=h; h = temp; } while (h != 0) { n = w % h; w=h; h = n; } return w; } 최소공배수 LCM(Least Common Multiple) (각 숫자 / 최대공약수) * 최대공약수 // 두 개만 비교할 때에 두 수의 곱 / 최대공약수가 최소공배수가 됨 순열과 조합(Permutatio..