I have a Glassfish server and I expect it to be rather loaded. For example, I have RESTful services and I want to make a request to Google API in the one of the methods. Should I create a new Thread to do such a work?
Asked
Active
Viewed 222 times
0
-
How exactly will creating a new thread change the work to be done? Or reduce the load? – user207421 Mar 17 '15 at 08:37
1 Answers
0
No, you should avoid managing anything with threads manually inside the Java EE world. This work is should be provided by the container (Glassfish in this case), especially for a HTTP response.
Inside of EJBs it is even prohibited:
The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt to start, stop, suspend, or resume a thread, or to change a thread’s priority or name. The enterprise bean must not attempt to manage thread groups.
(EJB 3.1 spec, page 599)
There are some exceptions where you may need to do something manually in a web application, but in general it should be avoided.
See also:

Community
- 1
- 1

unwichtich
- 13,712
- 4
- 53
- 66