====== Java ThreadLocal ====== * [[https://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html|ThreadLocal]] Each thread holds an implicit reference to its copy of a thread-local variable as long as the thread is alive and the ThreadLocal instance is accessible; after a thread goes away, all of its copies of thread-local instances are subject to garbage collection (unless other references to these copies exist). ===== withInitialValue ===== * 초기값을 생성하는 lambda 를 지정해두면 최초에 값이 없을 때에 적절한 초기값을 제공해준다. * ''remove()'' 를 호출해서 초기값이 없어진 상태에서 다시 ''get()''을 하면 ''withInitialValue''로 설정했다면 다시 초기값을 생성해서 반환해준다. ===== 참조 ===== * [[http://stackoverflow.com/questions/17968803/threadlocal-memory-leak|java - ThreadLocal & Memory Leak]]