Re: ***Please reply as no one on this list has offered ANY help***

2002-05-21 Thread Rick Fincher

Hi Stuart,

It looks as if you have a problem with instance variables (variables in a
class declared outside a method). All logins are going to be using the same
copy of the code, i.e. same variable space etc.  All synchronizing does is
make sure that the threads play nice when modifying the variables.

Your Hashtable "connections" is an instance variable, so there is only one
copy of it for all calls to connections.  When you fill "connections" with
data, another login may fill it again before you get a chance to copy that
data to a new object.

Also, all those instance variables at the top of your thread class
"ToApplet" are all shared by all instances of "ToApplet".  Every thread is
going to see what was stuffed into them by the last thread created.
Generally you should only do that for data that needs to be the same for all
threads and is initialized once and never changed.

In general, if you are storing anything in an instance variable you might
have problems.  Create a class to hold data and use it instead.

As a simple example, instead of :
String myStr = req.getParameter("blaBla");

use:
StorageClass myData = new StorageClass();
myData.myStr = req.getParameter("blaBla");

That way, you are certain to get a clean one-owner copy of myStr for each
thread as long as you are careful to create and fill it in a sync block.

If you need another method to see your object pass it as a parameter.

The same thing will happen in a JSP if you create a class inside <%! %> and
then call that object's methods with variables in the main JSP page.
Although each call to the JSP will create a new class

Hope this helps,

Rick

>
> Hello,
>
> I'm having touble with my HTTP tunnelling servlet and its driving me
crazy.
> The tunnel works fine for a single user. However when another user
connects
> to the tunnel the servlet does not perform how I would expect it to.
>
> The problem is, that when another user sends a message. ALL instances of
the
> variables seem to swap over to the most recent. However the threads still
> all run. So, if mr x and mr y are in a meeting. Mr x joined first, he says
> 'hello'. Hello is sent and recieved once how I would expect it to do it.
> However, now mr y joins and says 'hello'. and he recieves the messages for
> himself AND for mr x.
>
> This is driving me insane and I can't seem to find a way around it, I
don't
> understand why the entire data structure is being overwritten when it is a
> different request for a different user. The sockets are different, yet
when
> i do the test, they aren't! But the server isnt sending the message out on
> the wrong socket. I've tested that. It's somehow the right sockets,
> recieving the right messages, but then sending them to the wrong place.
But
> how can this be? It makes no sense to me.
>
> The code for the tunnel is below.
>
> Stuart Stephen
>
>
> import javax.servlet.*;
> import javax.servlet.http.*;
> import javax.servlet.ServletException.*;
> import javax.servlet.UnavailableException.*;
> import java.lang.Exception.*;
> import java.io.*;
> import java.util.*;
> import java.net.*;
>
> public class TestTunnel extends HttpServlet {
>
>   Hashtable connections = null;
>
>   protected void service(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException  {
> try {
>   String method = (String)req.getParameter("method").trim();
>
>   if(method!=null && !method.equalsIgnoreCase("")) {
> if(method.equalsIgnoreCase("connect")) connectUser(req, res,
> (String)req.getParameter("mid").trim(), "",
> (String)req.getParameter("email").trim());
> else if(method.equalsIgnoreCase("msg"))
> msgServer((String)req.getParameter("mid").trim(), "",
> (String)req.getParameter("email").trim(),
> (String)req.getParameter("msg").trim());
> else {
>   System.err.println("redirecting user");
>   res.sendRedirect("http://www.disney.com";);
> }
>   }
> }
> catch(Exception e) {
>   e.printStackTrace();
> }
>   }
>
>   protected synchronized void msgServer(String mid, String uid, String
> email, String msg) {
> if(connections!=null) {
>   try {
> System.err.println("msgServer()");
> Hashtable meet = (Hashtable)connections.get(mid+""+uid+""+email);
> if(meet!=null) {
>   ((ToServer)meet.get("ToServer")).write(msg);
> }
> else System.err.println("msgServer(): meet == null");
>   }
>   catch(Exception e) {
> e.printStackTrace();
>   }
> }
> else System.err.println("msgServer(): No connections to use.");
>   }
>
>   protected void connectUser(HttpServletRequest req, HttpServletResponse
> res, String mid, String uid, String email) {
> try {
>   System.err.println("CONNECTING "+mid+""+uid+""+email);
>
>   Socket socket = new Socket("127.0.0.1", 3000);
>   ToApplet app = new ToApplet(socket, res, mid, uid, email);
>   ToServer ser = new ToServer(socket, req, mid, uid, ema

RE: ***Please reply as no one on this list has offered ANY help***

2002-05-21 Thread Stuart Stephen

Nah, I put meet.clone() as a test, I just didn't take it off again.

I've been told by someone on the list to try using the session to reference
things instead. I'll have to give that a go before I continue asking
questions.

Thank you for a response.

-Original Message-
From: Denis Haskin [mailto:[EMAIL PROTECTED]]
Sent: 21 May 2002 22:38
To: Tomcat Users List
Subject: Re: ***Please reply as no one on this list has offered ANY
help***


Without digging in too deeply, is it possible your problem is the cloning of
the
'meet' Hashtable in connectUser?

Remember that cloning a Hashtable (and other Collection/Dictionary objects)
is a
shallow clone.  Only the table itself is cloned, not the objects pointed to
by
the table.

I'm not *sure* that's a problem in this case, but is that what you intend?
It's
not clear to me why you're cloning it there, anyway...

dwh


Stuart Stephen wrote:

> Hello,
>
> I'm having touble with my HTTP tunnelling servlet and its driving me
crazy.
> The tunnel works fine for a single user. However when another user
connects
> to the tunnel the servlet does not perform how I would expect it to.
> [...]


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: ***Please reply as no one on this list has offered ANY help***

2002-05-21 Thread Denis Haskin

Without digging in too deeply, is it possible your problem is the cloning of the
'meet' Hashtable in connectUser?

Remember that cloning a Hashtable (and other Collection/Dictionary objects) is a
shallow clone.  Only the table itself is cloned, not the objects pointed to by
the table.

I'm not *sure* that's a problem in this case, but is that what you intend?  It's
not clear to me why you're cloning it there, anyway...

dwh


Stuart Stephen wrote:

> Hello,
>
> I'm having touble with my HTTP tunnelling servlet and its driving me crazy.
> The tunnel works fine for a single user. However when another user connects
> to the tunnel the servlet does not perform how I would expect it to.
> [...]


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: ***Please reply as no one on this list has offered ANY help***

2002-05-21 Thread Phillip Morelock

alright.  leaving aside the issue of your subject line...

I, too, am not reading all that code until I get a better idea of what
you're actually asking.  For instance, do you know the following?

only ONE instance of a servlet is created in the servlet container.  That
means that every request hits the same instance method, instance variables,
etc, just as though they were static.  I haven't bothered to look over your
threads, but what are they doing and what global data do they reference?





On 5/21/02 2:20 PM, "Stuart Stephen" <[EMAIL PROTECTED]> wrote:

> I've not declared any variables as static
> 
> -Original Message-
> From: Ray Letts [mailto:[EMAIL PROTECTED]]
> Sent: 21 May 2002 22:18
> To: Tomcat Users List
> Subject: Re: ***Please reply as no one on this list has offered ANY help***
> 
> 
> 
> A quick question without going over all that code:
> 
>> The problem is, that when another user sends a message. ALL instances
>> of the
>> variables seem to swap over to the most recent.
> 
> 
> 
> static variables? these get instantiated once per class not per object
> and thus would act as you have said they are.
> 
> ray
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




RE: ***Please reply as no one on this list has offered ANY help***

2002-05-21 Thread Stuart Stephen

I've not declared any variables as static

-Original Message-
From: Ray Letts [mailto:[EMAIL PROTECTED]]
Sent: 21 May 2002 22:18
To: Tomcat Users List
Subject: Re: ***Please reply as no one on this list has offered ANY help***



A quick question without going over all that code:

 >The problem is, that when another user sends a message. ALL instances
 >of the
 >variables seem to swap over to the most recent.



  static variables? these get instantiated once per class not per object
and thus would act as you have said they are.

ray


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Re: ***Please reply as no one on this list has offered ANY help***

2002-05-21 Thread Ray Letts


A quick question without going over all that code:

 >The problem is, that when another user sends a message. ALL instances 
 >of the
 >variables seem to swap over to the most recent.



  static variables? these get instantiated once per class not per object 
and thus would act as you have said they are.

ray


--
To unsubscribe, e-mail:   
For additional commands, e-mail: