I'm getting some strange results sending multiple asynchronous AJAX calls to the same java servlet at the roughly the same time.
For example, let's say I send off two AJAX requests at the same time using jQuery.
//ajax call foo
$.post('LookupServlet', {
method: 'findFoo'
};
//ajax call bar
$.post('LookupServlet', {
method: 'findBar'
};
In my servlet it invokes the given method. The method writes a response to the stream.
What is strange is that that foo sometimes gets the response for bar. And vice versa. Or sometimes one ajax call is getting both responses. Or one request gets a response and the other one doesn't.
I've never seen anything quite like this before in other server-side languages, I didn't even know it was possible. Does anyone have any theories as to why this is happening? How do Java servlets operate where simultaneous requests could get crossed responses?