• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet problem - help required

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you've solved your problem.
When people have a question about threading issues in Servlets, I usually point them here.
Dave.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic