본문 바로가기

예외 Java 예외 - java 예외에는 Error와 Exception으로 나뉜다. - 모두 Throwble을 상속한다. Error - 개발자가 Control 하지 못하는 예외이다. 대표적으로 OOM와 StackOverFlow가 있다. Exception - Exception에는 CheckedException과 UnchkedException이 있다. Checked Exception - 예외를 핸들링하지 않으면 Compile 시점에 Compile Error가 발생한다. - 예외를 핸들링하여 장애 상황을 미리 대처할 수 있다. - 대표적으로 IoException과 CheckedException 있다. Unchecked Exception - Runtime Exception이다 - 예외를 핸들링 하지 않아도 Compi..
SpringBoot 세팅할 때 DatasSource Exclude Spring boot를 세팅할때 DB를 사용하지 않고 세팅하고 싶을 때가 있다. 이럴때 기본 설정으로 세팅을 하면 아래와 같은 에러가 발생한다.이유는 Spring boot는 기본적으로 db설정을 읽어서 세팅하는것 같다. Description: Cannot determine embedded database driver class for database type NONE Action: If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profil..
Reduce Max값 구하기 1. Collectors reducing을 이용하는 방법 Food food = Food.menu.stream().collect(Collectors.reducing((d1, d2) -> d1.getCalories() > d2.getCalories() ? d1 : d2)).get(); 2. Collector maxBy를 이용하는 방법, 내부적으로는 Collectors의 reduce를 호출 함.Food food1 = Food.menu.stream().collect(Collectors.maxBy(Comparator.comparingInt(Food::getCalories))).get(); 3. Stream reduce를 이용하는 방법Food food2 = Food.menu.stream().reduce((d1, d..
수열의 결과값을 구하는 프로그램 아래 수열의 결과값을 구하는 프로그램을 작성하시오. 1 - 2 + 3 - 4 + 5 - ..... + 99 - 100 = ? - 1부터 계산하는 경우 private static void plusMinusSequence() { int result = 1; for (int i = 1; i < 100; i++) { if (i % 2 == 0) { result += i + 1; } else { result -= i + 1; } } System.out.println(result); } - 0부터 계산하는 경우 private static void plusMinusSequence2() { int sum = 0; for (int i = 0; i b % 2 !=0 ? a + b : a - b)); System.out.p..
클라우데라매니저 설치 클라우데라 설치 root로 download sudo wget http://archive.cloudera.com/cm5/installer/5.11.0/cloudera-manager-installer.bin sudo chmod 755 cloudera-manager-installer.bin
락 public class UnsafeCachingFactorizer implements Servlet{ private final AtomicReference lastNumber = new AtomicReference(); private final AtomicReference lastFactors = new AtomicReference(); @Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception { BigInteger i = extractFromRequest(servletRequest); if (i.equals(lastNumber.get())) { encodeIn..
스레드 안전성 java 동기화 기본 수단 - 자바에서 동기화를 위한 기본 수단은 syncronized 키워드로서 베타적인 락을 통해 보호 기능을 제공 함. - volatile 변수, 명시적 락, 단일 연산 변수 (atomic variable)을 사용하는 경우에도 동기화 용어를 사용함. 여러 스레드가 변경할 수 있는 하나의 상태 변수를 적절한 동기화 없이 접근하면 그 프로그램은 잘못된 것. 프로그램을 고치는 3가지 방법 - 해당 상태 변수를 스레드 간에 공유하지 않거나 - 해당 상태 변수를 변경할 수 없도록 만들거나 - 해당 상태 변수에 접근할 땐 언제나 동기화를 사용 상태 없는 서블릿 - 서블릿 기반 인수분해 서비스를 만들고 스레드 안정성을 유지하면서 하나하나 기능 추가@ThreadSafe public class St..
필드에 값 넣기 Test케이스 작성 시 Spring에서 @Value로 값을 받을 경우 해당 필드를 초기화 해줘야 하는데ReflectionTestUtils.setField(purchaseDeliveryRequestController, "purchaseAdminRoleIdList", Arrays.asList("tes1", "test3"));이런식으로 값을 초기화 할 수 있음 자꾸 까먹어서 남김.