Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat's behaviour when two simultaneous requests come from same ip

Tags:

java

tomcat

When i try to run 2 wget commands simultaneously to my server (http://myserver), looks like tomcat allocates two threads to process them. But i believe when tomcat receives two simultaneously from same ip address, it will not create a new thread for processing the second request as it considers both the requests come from same session.

If i want to check if both the threads are same or different, is using thread.getId() the only way? I think this id may be reused for new threads. Is there any unique property of the thread existing to check its identity other than threadid?

like image 311
ihavprobs Avatar asked Apr 26 '26 05:04

ihavprobs


2 Answers

I suggest to never rely on threads to identify their source. There are no Servlet spec guarantees about threads, and newer Servlet spec implementations make use of NIO. You are skating on a thin ice.

like image 135
mindas Avatar answered Apr 27 '26 19:04

mindas


Web servers will almost always assign multiple threads (or processes) to multiple simultaneous requests, since the client can work faster when it does not have to wait for each response.

Newer servers may use asynchronous IO (nio), however, and a single thread can simultaneously serve many clients.

Yes, Thread.getId() is a way of identifying threads.

Session IDs are the mechanism used to identify requests from a single client.

The IP address is not a good way to do that, since multiple machines can expose the same IP when hiding behind a NAT.

like image 20
Joshua Fox Avatar answered Apr 27 '26 18:04

Joshua Fox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!