1

In a B/S web system(J2EE, Jsp,servlet ),if user a and user b click the same button at the same time.

Do they create two new threads on the server side?

If a static method will be called in that button event, will that two new threads access the static method concurrently?

If so, should I care about the thread-safe issue?

It would be very appreciated if someone may explain this to me,thank you.

bestoak
  • 33
  • 5

1 Answers1

0

as I know, this would be an IO problem. Whether a new thread will be created depends on the way how your server works. But actually most commercial web system would maintain their own threads pool, in which certain number of threads(How many depends on the configuration and the hardware of the server)exists, once a client send a new request to the server, it would be in the producer channel (if it use a NIO), and if there exists any consumer thread get spare time, it would take over this request and start the procedure of this request.

Suggest that you may take a look at the IO protocol, also some common used web structure such like Netty, Jetty and so on.

Here are some links that may help for your confuse:

What is the difference between Tomcat's BIO Connector and NIO Connector?

Java BIO, NIO, AIO understanding

Community
  • 1
  • 1
chrischeng021
  • 123
  • 10
  • So no matter the thread is a new one or not, there will be two threads dealing with user a and b's requests.thus there's a possibility that two threads will call a static method concurrently. And if the static method is not synchronized, there will be some problems. – bestoak Apr 28 '17 at 11:42
  • So your problem is about the synchronized situation on the static function called by several parallel threads? Then I think what you need to do is just to guarantee the shared variables should be edited by only single thread....Actually I still get doubt about what's your main problem is...Is it the multiply threads, or the lock contention problem? – chrischeng021 May 05 '17 at 07:41