전체 글 (52) 썸네일형 리스트형 [NIO] Socket Channel 채널은 파일, 소켓, 데이터그램 등과 같은 다양한 I/O 소스로부터 데이터 블록을 버퍼로 쓰거나 읽어온다. 네트워크 프로그래밍을 위해서는 SocketChannel, ServerSocketChannel, DatagramChannel 세개가 가장 중요하다. 그리고 TCP 연결을 위해서는 이 중에서도 앞의 두 개의 채널만 필요하다. 1. SocketChannel class SocketChannel 클래스는 TCP 소켓에 대해 읽고 쓴다. 읽고 쓸 데이터는 ByteBuffer 객체로 먼저 인코딩 되어야 한다. 각각의 SocketChannel 은 Socket 객체와 연결되어 있다. 연결하기 SocketChannel 클래스는 public 으로 선언된 생성자를 제공하지 않는다. 대신에 다음 두 정적 open() 메소.. [leetcode][hard] Maximum Profit in Job Scheduling We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i]. You're given the startTime, endTime and profit arrays, return the maximum profit you can take such that there are no two jobs in the subset with overlapping time range. If you choose a job that ends at time X you will be able to start another job that starts at time X. Exampl.. 뮤텍스(Mutex) VS 모니터(Monitor) 간단하게 말해서 Monitor 는 Mutex + Condition Variable 이다. Monitor 의 이해를 돕기 위해 아래 코드를 살펴보자. 아래 코드를 보면 predicate 라는 부분이 나오는데, 이 부분은 스레드간 선제조건을 의미한다. 즉, 이 값이 true 가 되었다는 것은 이전에 인과의 관계에 속해있는 사전 작업이 완료되었다는 것을 의미하고 그때 현재 스레드의 작업을 수행할 수가 있다. void example() { // acquire mutex while (predicate is false) { // release mutex // acquire mutex } // do something in this thread. // release mutex } 위 코드의 flow 를 보면, 먼저 m.. 이전 1 2 3 4 5 6 7 ··· 18 다음