Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java jax-ws server threads  RSS feed

 
John Jenson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I have a question about threading in java web services. When I deploy a WAR file on Tomcat and start it, how many threads it can handle? I suppose that i tell Tomcat how many threads to handle, but where and how. And the next and more important question is what happens when 2 clients connect at the same time? Are two instances of the web service automatically created or the two clients just use the one instance - the actual web service ?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into TOMCAT_HOME/conf/server.xml. The <Connector> elements (there is one for HTTP and one for HTTPS, although the latter is commented out by default) have maxThreads attributes that you can alter. Note that this is for the entire Tomcat instance, not for each web app. See http://tomcat.apache.org/tomcat-7.0-doc/config/http.html for details.

Most WS engines create one instance of the WS class for each request, so you should keep the startup overhead of that class at a minimum - anything that takes noticeable time to initialize should be static, and made properly thread-safe. I'm not sure if the JAX-WS spec actually requires that, or if that's an implementation detail that might differ between the various WS engines.
 
John Jenson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. Well I made all my WebMethods synchronized with blocks. So I don't need to worry about multi threading ? Also I have an Authentication @HandlerChain and I don't know what happens behind the hood with this handler. Is it only one for the whole class or it creates different instances for every method ?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made all my WebMethods synchronized with blocks.

That is unnecessary as far as instance variables are concerned. It might make sense if you have a lot of shared mutable state, but generally, synchronizing entire methods causes too much of a hit on concurrency.

So I don't need to worry about multi threading?

You need to worry about concurrency wherever you have shared mutable state. For example, if you have a HashMap containing some data that is shared by all threads, you need to ensure proper synchronization if any of the threads alters the data it contains. But synchronizing a method only ensures that this particular method is not executed concurrently. If the HashMap is available in other classes as well, that doesn't protect you (unless you synchronize on that object).

Also I have an Authentication @HandlerChain and I don't know what happens behind the hood with this handler. Is it only one for the whole class or it creates different instances for every method ?

Not sure. Start with the JAX-WS documentation, and move on to the SOAP engine docs if the JAX-WS spec doesn't address this.
 
John Jenson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mmh thank you a lot for the answers!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!