기본 콘텐츠로 건너뛰기

자바 스트림 재사용

은 불가하다. 조금더 구체적으로 말하면 스트림 함수중 내부적으로 reduce()를 호출하는 경우에 불가능하다. 이렇게 설계한 배경은 조금더 찾아봐야 하겠지만 불가능한 이유는 다음과 같다. IntStream의 sum()의 구현체다 sum() 함수는 다음 순서대로 진행된다.  sum() -> reduce() -> AbstractPiplie.evaluate() abstract class IntPipeline< E_IN > extends AbstractPipeline< E_IN , Integer , IntStream> implements IntStream { .... @Override public final int sum () { return reduce( 0 , Integer:: sum ) ; } ... @Override public final int reduce ( int identity , IntBinaryOperator op) { return evaluate(ReduceOps. makeInt (identity , op)) ; } } 그리고 evaluate함수는 상속받은 AbstractPipeLine에 구현되어있다. 처음 호출되었을때 해당 파이프라인의  linkedOrConsumed  를 true로 변환하고 이후에 호출되었을시 예외처리를 하게끔 되어있다.    abstract class AbstractPipeline< E_IN , E_OUT , S extends BaseStream< E_OUT , S >> extends PipelineHelper< E_OUT > implements BaseStream< E_OUT , S > { private static final String MSG_STREAM_LIN...

오라클 java 유료화

1. 개요   - 2019년 1월 1일부로 Oracle Java의 업데이트는 유료 사용자에 한에 지원 받을 수 있게 되어 이에 대한 대응책이 필요함.  즉, 기존의 Oracle Java의 사용은 가능, 하지만 유료 전환을 하지 않을 경우 현재의 사용하고 있는  Oracle Java가 본인이 사용하는 마지막 Java임  2. 지속적으로 Oracle Java를  유지할 경우 발생할 수 있는 문제점  - 기존 자바의 중요결함 발생시 배포되는 업데이트를 받을 수 없음  - 자바의 신규기능을 사용할 수 없음 3. Oracle Java 가격정책  1인당 2.5달러/월, 1프로세서당 25달러/월을 기본으로 하며 전체 규모에 따라 할인  - 사용자별 Volume Subscription Metric Monthly Subscription Price 1-999 Named User Plus $2.50 1,000-2,999 Named User Plus $2.00 3,000-9,999 Named User Plus $1.75 10,000-19,999 Named User Plus $1.50 20,000-49,999 Named User Plus $1.25 50,000+ Contact for details  - 프로세서별 Volume Subscription Metric Monthly Subscription Price 1-99 Processor $25.00 100-249 Processor $23.75 250-499 Processor $22.50 500-999 Processor $20.00 1,000-2,999 Processor $17.50 3,000-9,999 Processor...

Integer - java

최대 최소값 최소 -2의 31승 / 최대 2의 31승-1 @Native public static final int MIN_VALUE = 0x80000000 ; @Native public static final int MAX_VALUE = 0x7fffffff ; toString() - 10진수를 다른진법으로, 문자열로 변환 Integer . toString ( 10 ) // 10 Integer . toString ( 10 , 2 ) // 1010 Integer . toString ( 10 , 5 ) // 20 toBinaryString(), toOctalString, toHexString() 자주사용하는 2진수, 8진수, 16진수는 별도함수가 있다. Integer . toBinaryString ( num ) // 1010 Integer . toOctalString ( num ) // 12 Integer . toHexString ( num ) // a valueOf() IntegerCache 사용(-128~127) cache범위가 벗어날때는 새로운 Integer객체를 생성 public static Integer valueOf ( int i ) { if ( i >= IntegerCache . low && i <= IntegerCache . high ) return IntegerCache . cache [ i + ( - IntegerCache . low ) ] ; return new Integer ( i ) ; } equals() 타입이 Integer인지, 값이 같은지 public boolean equals ( Object obj ) { if ( obj instanceof Integer ) { return value == ( (...

스프링부트, logging

Logging 스프링부트는 Java Util Logging, Log4j2, Logback을 기본적으로 제공한다. 내부적으로 apache common logging 을 사용하나 변경이 가능하다 만약 ‘Starters’를 사용한다면 Logback이 사용된다. Log Format 시간/로그레벨/process id/ 구분자(—)/ thread 명/ logger 명 / 메세지 2014-03-05 10:57:51.112 INFO 45469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52 2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1358 ms Color-coded Output 로그에 색을 입힐 수도 있다. spring.output.ansi.enabled 값을 설정해주면 된다. Enum Constants Enum Constant Description ALWAYS Enable ANSI-colored output. DETECT Try to detect whether ANSI coloring capabilities are available. NEVER Disable ANSI-colored output. File Output 기본적으로 스프링 부트는 파일에는 로그를 남기지 않고 콘솔에만 표시한다. ...

스프링부트, Externalized Configuration

환경변수 설정 설정파일을 어플리케이션 밖에서 관리함으로써 같은 어플리케이션으로 여러가지 설정을 변경하면서 운영할 수 있다. Properties files, yaml files, environment variable, command-line arguments 사용 @Value 어노테이션을 통해 주입받을 수 있다. 우선순위 스프링부트에서는 환경변수값을 읽는 우선순위가 있다. 만약 예사외의 값이 적용되었다면 아래 순위를 확인해보자 devtools -> test관련 -> command line -> servlet -> Jndi -> system property -> environments -> random -> properties file -> @Configuration classes 1. [Devtools global settings properties](https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools-globalsettings) on your home directory (~/.spring-boot-devtools.properties when devtools is active). 2. [@TestPropertySource](https://docs.spring.io/spring/docs/5.0.5.BUILD-SNAPSHOT/javadoc-api/org/springframework/test/context/TestPropertySource.html) annotations on your tests. 3. [@SpringBootTest#properties](https://docs.spring.io/spring-boot/docs/2.0.1.BUILD-SNAPSHOT/api/org/springframework/boot/test/context/Spr...

스프링부트, SpringApplication 클래스

springApplication SpringApplication 스프링 어플리케이션을 간편하게 실행할 수 있도록 제공하는 클래스 main()함수를 통해 실행되며, 기본 로그 수준은 info 이다. The following example shows potential logging settings in application.properties: logging.level.root=WARN logging.level.org.springframework.web=DEBUG logging.level.org.hibernate=ERROR FailureAnalyzers 스프링 실행시 오류가 발생하면 에러메세지와 해결 방법을 제시해준다. \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* APPLICATION FAILED TO START \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Description: Embedded servlet container failed to start. Port 8080 was already i n use. Action Identify and stop the process that's listening on port 8080 or configure this application to listen on another port. customizing the Banner 스프링 실행시에 로딩되는 배너를 수정할 수 있다. classpath에 존재하는 banner.txt를 수정 (spring.banner.location) 텍스트 파일 대신에 이미지도 가능하다 (spring.banner.image.location) 스프링 부트 생성기 https://devops.datenkollektiv.de/banner.txt/index.html SpringA...

스프링부트, spring-boot-devtools

스프링부트에서 소스코드 수정시 자동으로 서버를 재시작 하는 기능등을 제공한다. maven dependencies < dependencies > < dependency > < groupid > org.springframework.boot </ groupid > < artifactid > spring-boot-devtools </ artifactid > < optional > true </ optional > </ dependency > </ dependencies > 자동 restart classpath가 변경되면 어플리케이션이 자동으로 restart ide마다 차이가 좀 있는데 eclipse는 저장시에 classpath 변경이 발생하지만, intellij는 build project 기능을 통해 진행된다. Restart vs Reload spring boot는 2개의 classloader를 사용 Base classloader : 변하지 않는 3rd party용 .jar파일같은 Restart classloader : 개발자가 직접 작성하는 클래스 같은 Restart 실행시에 base classloader가 미리 작업한 부분은 할필요하고 없으므로 효율적임 만약 restart 가 충분히 빠르지 못하게 작동한다면 JRebel의 reloading을 고려 Excluding Resources /META-INF/maven, /META-INF/resources, /resources, /static, /public, or /templates 이곳 폴더들은 변경이 일어나도 restart가 발생하지 않음 spring.devtools.restart.exclude= static /**,public/** 이런식으로 추가로 설정가능 Watching...