2023/04
번외편. ConcurrentHashMap
번외편. ConcurrentHashMap
2023.04.16ConcurrentHashMap ConcurrentHashMap은 동시성을 지원하는 해시맵 클래스입니다. 기본 HashMap 클래스와 마찬가지로 키-값 쌍을 저장할 수 있으나, ConcurrentHashMap은 멀티스레드 환경에서 동시성을 지원하기 위해 설계되었습니다. 멀티스레드 애플리케이션에서 여러 스레드가 동시에 맵에서 데이터를 읽고 쓰거나, 따로 동기화 블록을 사용하는 대신 ConcurrentHashMap이 제공하는 동시성 제어 메커니즘을 활용하려면 ConcurrentHashMap을 사용할 수 있습니다. public class ConcurrentHashMap extends AbstractMap implements ConcurrentMap, Serializable { // ... // 주어진 키에 해..
번외편. CompletableFuture
번외편. CompletableFuture
2023.04.12이 글은 보호되어 있기 때문에 이것을 보려면 암호가 필요합니다.
31편. 스레드(Thread) (4)
31편. 스레드(Thread) (4)
2023.04.09Callable과 Future Callable 기억을 되살려서 Runnable이 무엇이었는지 떠올려 봅시다. 전에 사용했던 Runnable은 실행이 끝난 후에 어떤 결과 값을 반환해 줄 수 없었으며, 예외가 발생할 수 있다고 throws 문을 통해서 표현할 수도 없었습니다. 하지만 Callable을 사용하면 결과 값도 돌려줄 수 있으며, 예외도 발생시킬 수 있도록 만들 수 있습니다. @FunctionalInterface public interface Runnable { public abstract void run(); } @FunctionalInterface public interface Callable { // 계산한 결과를 반환할 수 있는 메서드다. // 만약에 결과를 계산할 수 없으면 예외를 던질 ..
30편. 스레드(Thread) (3)
30편. 스레드(Thread) (3)
2023.04.07스레드의 상태 자바의 스레드는 총 6개의 상태(NEW, RUNNABLE, WAITING, TIMED_WAITING, BLOCKED, TERMINATED)를 가지고 있습니다. 참고로 자바의 스레드는 JVM(Java Virtual Machine, 자바 가상 머신) 위에서 돌아가며, 여기에 나와 있는 상태들은 가상 머신의 상태를 말하는 것입니다. 다시 말해서, 운영체제 스레드의 상태를 나타내는 것은 아닙니다. NEW 새로운 스레드를 만들면 NEW 상태가 됩니다. 이 상태의 스레드는 아직 시작되지 않았으며, start() 메서드를 호출하며 스레드를 시작하면 RUNNABLE 상태로 들어가게 됩니다. Thread thread = new Thread(new ThreadA()); System.out.println(th..