"Drizen, Alex (London)" wrote:
>
> Please help!
>
> I am using Borland JBuilder to develop a servlet which will accept multiple
> threads (and hence requests from users).
>
> In one of the opening screens, I am opening up a frame page, of which each
> part of the frame window is loaded by a GET request to the servlet - an
> example of the HTML frames page is given below :
>
> <FRAMESET rows="100,50,*" frameborder="0" framespacing="0" border="0">
> <FRAME src="http://127.0.0.1:8080/servlet/servlet?req=1" scrolling="no"
> marginheight="0" marginwidth="0">
> <FRAME src="http://127.0.0.1:8080/servlet/servlet?req=2" scrolling="no"
> marginheight="0" marginwidth="0">
> <FRAME src="http://127.0.0.1:8080/servlet/servlet?req=3" scrolling="no"
> marginheight="0" marginwidth="0">
> </FRAMESET>
>
> req=1, 2 and 3 are used to load up 3 different HTML screens respectively.
>
> The problem I am having is that sometimes these requests appear to be
> scrambled in the order they are processed and responded to by the servlet.
> For example, HTML page 1 may appear in frame window 2 or page 3 may appear
> in window 1, etc. - this happens at random and there is no set pattern as to
> how this is happening.
>
> I think the problem may stem from the fact that all requests are made at
> EXACTLY THE SAME TIME given the nature of the frames page.
>
> How can I ensure that each of these requests is processed in the correct
> window?
There should be no problem with the web server and servlet engine sending output
to the correct frame, no matter how many concurrent requests are made. It is
similar to the problem of multiple submits from different browser windows.
Earlier today I was testing some code where I had 6 different browser windows on
the same machine using Javascript to make each browser perform a submit to a
servlet at EXACTLY THE SAME TIME. There was no problem with the servlet
directing the response to the correct browser.
The probable cause is that your servlet is not thread-safe, contrary to your
assertion.
Do the other pages ever show up? Or is it the case that when one page appears in
the incorrect window, the other pages do not get displayed in any window? If
this is the behavior, then the problem is that your servlet is not thread safe.
You are likely using the output stream as an instance variable of your servlet.
As each request comes in, the output stream changes, which would explain why you
get page 1 in frame 2 or 3. If this is the problem, then the solution is to make
the output stream a method variable.
See the Java FAQ for more information on thread safety -
http://www.purpletech.com/servlet-faq/
K Mukhar
___________________________________________________________________________
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