简体   繁体   中英

How to make a web service in java that can be called by multiple users

I have a simple Web service in Java and Weblogic. In this web service, I have a method which receive some data, call another webservice, write in DB and then answer with result.

If I try it with only one call it works fine, but, if I've tried with Soap UI, creating a TestCase, where you can call the web service in multiple threads, sometimes, it works ok, but sometimes, when there are a call in the middle of another, the result is not correct.

The problem is that when I call web service method I init some variables I have to analyze and save in DB, so, if a call is interrupted, these variables are updated and when the first call finish, the result is not correct (they are with init values).

If I put synchronized in web service method it works, but I think it's not the best way to do it, because I want to allow multiple users at the same time.

What's is the best way to do this?

Thank you very much

when you start writing client specific applications, you're required to keep a data for client state in your DB. So, when each client accesses your web server with their cookie/session, you can get the client-id (encrypted in side cookie/session) and evaluate server-side parameters based on values of client in DB.

谢谢kolossus的评论,我已经解决了它删除全局变量并仅创建局部变量的问题,因此每次调用都将创建一个新变量而不覆盖公共变量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM