Combining instances helps not only in the fact that you can reuse objects (and avoid the expensive creation of objects), but also the application. the server to properly manage the download . This is the app. server, but you can usually specify max-pool-size , min-pool-size , pool-resize and timeout .
When the pool reaches its max-pool-size capacity, requests are submitted using existing instances and will be absent if the instance is not available in the expected time period. This may degrade the quality of service for the application, but at least it will not blow the application up. server. This is the same as with a web server.
A few notes about thread safety :
Sec. 4.3.13 "Serialization of Bean Methods Session"
The container serializes calls for each Bean session. Most containers will support many Bean session instances running simultaneously; however, each instance only sees a serialized sequence of method calls. Therefore, a Bean session should not be encoded as reentrant.
According to the EJB specification, all requests for a specific Bean instance are synchronized by the application. server. This, for example, allows a non-Bean session (SLSB) to store a database connection in one of its fields. SLSB fields must be temporary. (A Bean instance can be destroyed / recreated at any time.) Synchronized application. The server ensures that SLSB is thread safe. No application sync. server, the developer must make sure that SLSB is thread safe, that is, it should not have fields.
Note: it is rare that there are fields in an SLSB. Most SLSBs are thread safe in nature. I would not recommend storing a connection in a field, for example. It is better to get one in the method and release it in the method as soon as possible.
ewernli
source share