How to handle many clients from one servlet ?

M

Multicoder4002

Hi.

I'm programming a servlet that has to handle many client requests. The
problem is that the communication with more that one client
application is not working properly... here it is :

1 servlet (handling post requests only)
2 client applications (threads)

- client app 1 sends username_client_1
- client app 2 sends username_client_2
- client app 1 sends password_client_1
==> here, the servlet sometimes understands the login information as :
login=username_client_1 and password=password_client_2, instead of
login=username_client_1 and password=password_client_1

the same thing is happening in all the processes... I've tried to use
HttpSession object but that does not help me very much (we cannot
distinguish many clients all along the servlet process..)

If anyone helps ;) thanks in advance...
see ya
 
H

hiwa

Hi.

I'm programming a servlet that has to handle many client requests. The
problem is that the communication with more that one client
application is not working properly... here it is :

1 servlet (handling post requests only)
2 client applications (threads)

- client app 1 sends username_client_1
- client app 2 sends username_client_2
- client app 1 sends password_client_1
==> here, the servlet sometimes understands the login information as :
login=username_client_1 and password=password_client_2, instead of
login=username_client_1 and password=password_client_1

the same thing is happening in all the processes... I've tried to use
HttpSession object but that does not help me very much (we cannot
distinguish many clients all along the servlet process..)

If anyone helps ;) thanks in advance...
see ya

The critical part of you code is not properly synchronized per user
connection, or 'session' in Web app parlance.
 
R

Robert Olofsson

: Hi.
: - client app 1 sends username_client_1
: - client app 2 sends username_client_2
: - client app 1 sends password_client_1
: ==> here, the servlet sometimes understands the login information as :
: login=username_client_1 and password=password_client_2, instead of
: login=username_client_1 and password=password_client_1

Let me guess, you write servlets that have instance variables to keep
the username and password.

Basic rule of servlets is that they can not have instance variables
since several threads may be accessing the same servlet simultanious.
You can implement an interface if you want to have only one thread
serving the request.

/robo
 
M

Multicoder4002

Thank you ;) It's ok now. I've verified all the source code, and
effectively, many data were not properly "synchronized"... All is
right ;)
see ya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top