Reputation: 11
During a coding session for a project I ran into a doubt.
My doubt is, how title suggests, about how J2EE Application Server serves a single WebService Call.
When a call to a WS is made by a client, the J2EE AS create a new thread to serve it? I don't need to worry about multiple and simultaneous calls to a WS implementation, right? (which is a Operation and a method in Java)
Another doubt is about @Autowired in Spring (with singleton instantiation which is the default).
In this web application, I'm creating a Spring Context in the usual way, in the web.xml I put the usual tag which refers to a context-spring-xml config file using the ContextLoaderListener Spring class.
For instance:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-conf/spring-context.xml
</param-value>
</context-param>
In this case, for every bean which is @Autowired (with singleton) I've a single instance for the entire Application Server? Or every time a WS Call is made a thread is created and the single thread has its single instance of every defined bean in the spring xml config file?
Let's consider that the ServiceImplementation class is a spring bean itself, managed as singleton.
We use Apache Camel as ESB exposing service Consumer as SpringRouteBuilder classes.
Upvotes: 1
Views: 66
Reputation: 4120
When a call to a WS is made by a client, the J2EE AS create a new thread to serve it? I don't need to worry about multiple and simultaneous calls to a WS implementation, right?
Right. But you have to worry about your @Autowired singleton thread-safety. It must not have any instance variables used during process of request/response. It may have only configuration/setting properties.
In this case, for every bean which is @Autowired (with singleton) I've a single instance for the entire Application Server?
Not right. It will not be for the entire AS. It is in scope of your web application. That is about applications isolation from each other. That means when same @Autowired class defined in two different web applications' Spring contexts (e.g spring-context.xml in web.xml inside both WAR) - each application Spring context will have its own singleton.
Upvotes: 0