Robin Bajaj
Robin Bajaj

Reputation: 2092

JAX-WS web services thread safety and performance concerns

I understand from a few other posts and my understanding on JAX-WS web services they are not thread-safe. My web service is going to get called by 100's of clients and we need to be able to process around 200 transaction/second.

My web service is going to interact with database to perform its work, if i introduce the synchronized keyword around the code that access the database I essentially will ensure only one thread access the database at a time, I wonder if I will still be able to achieve the required throughput in this case. thanks in advance for your help.

I have been told to actually move the database access work into another class and instaniate that class at the method level that way I won't need to use the synchronized keyword and still achieve thread safety. Is that correct?

Upvotes: 3

Views: 2072

Answers (2)

Chase
Chase

Reputation: 3183

If you need transactions and thread safety why aren't you just using EJBs as your JAX-WS endpoints?

Upvotes: 2

Yair Zaslavsky
Yair Zaslavsky

Reputation: 4137

We need more info on the application.

In general - for performance in the case you describe + database access I recommend.

  1. Carefully plan your database - index where possible/makes sense, use views, etc...
  2. Try to use a database with a good locking mechanism (lock per row). This way when two requests access different rows, you will not suffer from whole table locking.
  3. Have your transactions as short as possible. If using EJBs - make sure the transaction scope for "read data" methods is not Required or RequiredNew (this might cause opening a transaction).
  4. If you do use synchronization - carefully use the proper lock. Don't be tempted to automatically used "synchronized" as its the easiest to code. Consider using ReaderWriterLock where possible.
  5. Consider using caching where possible, but carefully plan this, so your flows work on "relevant" data.

Start with these directions - I think you will see you can achieve your performance target like this.

Upvotes: 1

Related Questions