Hi,
I'm developing a chat
applet. Im using
Tomcat 3.2.2 server for this. Everything worked fine, until i noticed a critical problem.
A
servlet is used to send a message to a client. Now let me describe my problem. Consider a scenario in which A is chatting with B, and at the same time C is chatting with D. Sometimes, all of a sudden the message that was supposed to go to B goes to C or D. Its is a kind of intermittent error, which i find hard to fix. Let me give u a skeleton copy of my servlet code.
public class PSPsendDoc extends HttpServlet
{
public void init(ServletConfig cfg)throws ServletException
{
super.init(cfg);
}
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
try
{
...lines of code
}
catch(Exception e)
{
}
}
}
I read some where that this could be a problem with threading, coz my servlet can be called by several chat users at a time. Here i have a vector uis which contains the user list to which the message should go(there may be several users in the case of a group discussion). This vector uis is declared as a private variable. So i belive that some other
thread is filling this vector with its contents. I think id better make this vector a local variable. If u guys faced any similar probs, or have any idea about this prob, please let me know.
Im counting on u
Kindest regards
Saj