I open my JSP several times in a few tabs (Firefox) and send a request to my servlet. Every time i have a result 50. Every next time when i wait a response i need to wait (i guess there is a delay because a servlet is sleeping. But i thought so... There is only one servlet class. Will i have only one instance of servlet for all requests or N-instances of servlet for N-requests? And if i have separated threads for each request (a new thread for a new request) - why i have delay with response? (every time i need to wait longer)?
In fact i expected to have an concurrent access problem (100 -50 -50 -50...)
Will i have only one instance of servlet for all requests or N-instances of servlet for N-requests?
You will have one instance, so the "a" field will be shared between all threads, whether they happen concurrently or not.
But why do i have always the result 50.
I thought i will subtract 50 every time. (the result will be 50, 0, -50, -100... so on)
The code is fine and working correctly.
Actually you should try to go through your model class (Asynch) once again.
here x is an instance variable, so it is initialized only once when you create a object of Asynch class. So in get method basically you are subtracting 50 from x which is 100 in first iteration. So if condition gets true in first iteration and x is assigned a new value i.e. 50. from now on if condition will never gets true because 50 > 50 is false. So from now on each iteration the value of x remains unchanged and 50.
In this way you will get same value for each iteration.