SocketChannel의 read 메쏘드는 timeout이 존재하지 않습니다.
혹, SocketChannel 객체의 .socket() 메쏘드로 소켓객체의 타임아웃을 세팅해도 먹지 않죠.. ^^;;
그래서, non-blocking의 read 메쏘드에 대한 timeout은 busy waiting하는 형태로 타임아웃을 줄 수 있겠습니다..
혹, SocketChannel 객체의 .socket() 메쏘드로 소켓객체의 타임아웃을 세팅해도 먹지 않죠.. ^^;;
그래서, non-blocking의 read 메쏘드에 대한 timeout은 busy waiting하는 형태로 타임아웃을 줄 수 있겠습니다..
// 20초
long timeout = 20 * 1000;
long stime = new Date().getTime();
long rtime = 0L;
int rvalue =0;
int rvalues = 0;
while (rtime < timeout ) {
rtime = System.currentTimeMillis() - stime;
rvalue = channel.read(rbuffer);
if(rvalue == -1)
throw new Exception("connection closed");
rvalues = rvalues + rvalue;
if(rtime > timeout)
throw new Exception("read timeout exception");
if(rvalues >= 4)
break;
}
long timeout = 20 * 1000;
long stime = new Date().getTime();
long rtime = 0L;
int rvalue =0;
int rvalues = 0;
while (rtime < timeout ) {
rtime = System.currentTimeMillis() - stime;
rvalue = channel.read(rbuffer);
if(rvalue == -1)
throw new Exception("connection closed");
rvalues = rvalues + rvalue;
if(rtime > timeout)
throw new Exception("read timeout exception");
if(rvalues >= 4)
break;
}
'Java' 카테고리의 다른 글
| Java에서 LRUCache 사용과 문제 그리고 해결방안 (0) | 2011/03/02 |
|---|---|
| java nio scatter/gater (0) | 2010/12/07 |
| non-blocking SocketChannel에서 read() timeout 처리하기.. (0) | 2010/09/17 |
| non-blocking SocketChannel에서 끝까지 읽어오기.. (0) | 2010/09/15 |
| Socket, RMI및 JMS를 이용한 통신 프로그램의 성능 비교.. (0) | 2010/08/19 |