简体   繁体   English

如何在Java中制作可被多个用户调用的Web服务

[英]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. 我在Java和Weblogic中有一个简单的Web服务。 In this web service, I have a method which receive some data, call another webservice, write in DB and then answer with result. 在此Web服务中,我有一个方法来接收一些数据,调用另一个Web服务,用DB写,然后用结果回答。

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. 如果我只尝试一次调用就可以正常工作,但是,如果我尝试过Soap UI,则创建一个TestCase,您可以在其中调用多个线程中的Web服务,有时,它可以正常工作,但是有时,在另一个通话中间,结果不正确。

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). 问题是,当我调用Web服务方法时,我必须初始化一些必须分析并保存在数据库中的变量,因此,如果调用被中断,则这些变量将被更新,并且当第一次调用完成时,结果是不正确的(它们是带有初始值)。

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. 如果我将同步放在Web服务方法中,它可以工作,但是我认为这不是最好的方法,因为我想同时允许多个用户。

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. 因此,当每个客户端使用其cookie /会话访问您的Web服务器时,您可以获取客户端ID(在cookie /会话中加密)并根据数据库中client的值评估服务器端参数。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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