Is it safe for a Java servlet to spawn threads in order to satisfy a request?

后端 未结 5 1065
后悔当初
后悔当初 2020-12-11 10:01

Is it safe for my Java (Tomcat 8) web server to spawn threads in response to a HTTP request? I\'m seeing posts and forums where some people say it\'s absolutely fine, and ot

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 10:17

    In my opinion

    1. this idea has not sense if thread should give effect in same request (cit. in order to satisfy a request)
    2. may have sense (if done properly) when effect of thread (running / ended) will be visible in next requests (especially via AJAX). Most servlet frameworks have way how to do "in orthodox way" long operations.

    To be clear: this is not normal way to do typical everyday AJAX tasks (must divide design to "main" request and next children ajax requests, using your framework), but AJAX can present state of background long thread.

    In my conception Thread or equivalent can be started from few/rare request, far below limits etc, but if it is done from every request, it is very bad design.

提交回复
热议问题