Marc Krisjanous wrote:

> Hi all,
>
> I was wondering if there was some way of getting the thread name of a
> request that comes into a servlet?
>
> I would like to identify an individual request (thread) and I do not want to
> use the session id since the request may come from a child web browser
> window (which would have the same session id).
>
> Best Regards
>
> Marc
> [...]

Hi :-)  I did a simple test :

*   enviroment:  jakarta-tomcat-4.0-b1(stand alone) on windows.

*   testing code:
   ...
   public void service(...){
      HttpSession session = req.getSession(false);
      if(session==null) session = req.getSession(true);

   System.out.println( "session.getId()="+session.getId() );
   System.out.println( "Thread.currentThread().getClass().getName()="+
            Thread.currentThread().getClass().getName() );
   System.out.println( "Thread.currentThread().getName()="+
            Thread.currentThread().getName()  );
   System.out.println( "Thread.currentThread().hashCode()="+
            Thread.currentThread().hashCode() );
   System.out.println( "\n" );

   try{
      Thread.currentThread().sleep(5000);
   }catch(Exception e){ System.out.println( "in Thread sleep, e="+e ); }

      res.setContentType("text/html");
      PrintWriter out = res.getWriter();
      out.println("<html><body>");
      out.println("in service, ok, haha");
      out.println("</body></html>");
      out.close();
   }
   ...


*  analyzing:
   -  I use two instances of NN4.7 to test it:
       one NN4.7 instances which is start by "double-click from desktop :-) "
       another NN4.7 instances which is started from the "File/New/Navigator
       Window of the first one"

   -  the following are same in two request from two NN4.7 instances:
      session.getId()
          and
      Thread.currentThread().getClass().getName()
         and
      Thread.currentThread().getName()

   -  sometimes the following are same in two request from two NN4.7
      instances, but sometimes they are not same:
      Thread.currentThread().getName()  );
         and
      Thread.currentThread().hashCode() );

      I think there is a "thread pool":  because if I request MySevlet from the
2
      NN4.7 instances with "interval <5s", I will get two different hashCodes
      of the thread.  But  if "interval >5s", I often/always get the same
hashCode
      of the thread.

    -  so I just guess perhaps we can Not use "HttpSession + Thread" to identify

       a special session( several instances of one_browser  <->  one_wepapp).



Bo
Feb.23, 2001

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to