java

[java]Pushlet

gonGon 2008. 9. 2. 16:42

www.pushlet.com

stateless인 http 통신을 state 유지로 바꾸어 주기 위한 꼼수이다.

구글 웹채팅 구현 기술을 논의하다가 조현선 과장님이 생각해 내었던 아이디어인데

pushlet이란 기술로 명명되어서 많이 쓰이고 있었다.

jsp나 servlet에서 publish하지 않고 for문을 돌리는 것이다.

for문 안 쪽에는 thread.sleep(sec.)으로 실행 주기를 준다.

web서버의 session 유지 기간 설정에 의해 stateless가 되므로

client에서는 주기적으로 (보통 30분 이내) jsp나 servlet을 재호출해야 할 필요가 있다.

아래 코드를 보자


<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <meta http-equiv="Pragma" content="no-cache">
</HEAD>
<BODY BGCOLOR="blue" TEXT="white">
<%
  try {
    for (int i=1; i < 10; i++) {
       out.print("<h1>"+i+"</h1>");
       out.flush();

       try {
            Thread.sleep(3000);
       } catch (InterruptedException e) {
            out.print("<h1>"+e+"</h1>");
       }
     }
   } catch (Exception e) {
       out.print("<h1>"+e+"</h1>");
   }
   out.print("<h1>DONE</h1>");

%>
</BODY>
</HTML>



간단한 아이디어지만 효과는 놀랍다.