请教,webservice远程调用方法的同步解决办法~
一客户提交一远程方法,提交中,程序经过处理,修改数据库
但是这同一客户同一时间2台电脑提交或者多个客户端提交,如何能禁止他同时提交而修改数据库错误
而在同一时间,必须要允许其他用户提交过来请求.
服务器程序如下:
public class BusinessService { //无效 public synchronized int send(String account, String password) { //无效synchronized(this){} public int send(String account, String password) { //里面代码省略 int i=0; return i; } //其他方法省略}public class Call { public static void main(String[] args) { BusinessService bs = new BusinessService(); bs.setWebService("http://127.0.0.1:8080/Server/services/BusinessService"); System.out.println(bs.send("test1", "1")); }}public class BusinessService { private static Object lock = new Object(); public int send(String account, String password) { synchronized(lock) { //里面代码省略 int i=0; return i; } } //其他方法省略}
[解决办法]
加个队列是否可以呢
如果要满足你说的要求,动态维护多个队列,如果并发量很大的话,需要再想想其他方式,或者程序性能比较高才行