Is it safe to inject an EJB into a servlet as an instance variable?

前端 未结 4 1265

We all know that in the web tier there is the possibility that only a single instance of a given Servlet exists which services multiple requests. This can lead to threading issu

4条回答
  •  旧巷少年郎
    2021-02-07 22:13

    I think the simple answer is that you aren't guaranteed that it is safe.

    The reason for this is that there is nothing explicit in the EJB specification that says EJB home interfaces have to be thread safe. The spec outlines the behaviour of the server side part only. What you will probably find is that the client skeletons are actually thread safe but you would need to look at how they are implemented by the library you are using. The annotation part will just expand into a service locator so that doesn't buy you anything.

提交回复
热议问题