当我同时做两个请求时,我的回报是混合的。
我在浏览器上进行测试。
TAB 1
localhost:8089/WebApplication2/resources/teste1?rep=2&clone=2
RETURN
{"codRepresentante":2,"codRetWS":100,"msgRetWS":"WebService de teste consumido com sucesso"}
TAB 2
localhost:8089/WebApplication2/resources/teste1?rep=1&clone=1
RETURN
{"codRepresentante":2,"codRetWS":100,"msgRetWS":"WebService de teste consumido com sucesso"}
我该如何解决? 我的代码怎么了?
RETORNO1WS.JAVA
package base;
public final class Retorno1WS {
private static int CodRetWS;
private static int CodRepresentante;
private static String MsgRetWS;
public synchronized int getCodRetWS() {
return Retorno1WS.CodRetWS;
}
public synchronized void setCodRetWS(int CodRetWS) {
Retorno1WS.CodRetWS = CodRetWS;
}
public synchronized int getCodRepresentante() {
return Retorno1WS.CodRepresentante;
}
public synchronized void setCodRepresentante(int CodRepresentante) {
Retorno1WS.CodRepresentante = CodRepresentante;
}
public synchronized String getMsgRetWS() {
return Retorno1WS.MsgRetWS;
}
public synchronized void setMsgRetWS(String MsgRetWS) {
Retorno1WS.MsgRetWS = MsgRetWS;
}
}
TESTE1WS.JAVA
package ws;
import base.Retorno1WS;
import java.sql.SQLException;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.ws.rs.*;
@Stateless
@Path("/teste1")
public class Teste1WS {
/**
*
* @throws SQLException
*/
public Teste1WS() throws SQLException, Exception {
super();
}
@GET
@Produces("application/json")
public synchronized Retorno1WS getTeste(@DefaultValue("0") @QueryParam("rep") int CodRep) {
Retorno1WS RetWS1 = new Retorno1WS();
RetWS1.setCodRetWS(100);
RetWS1.setMsgRetWS("WebService de teste consumido com sucesso");
RetWS1.setCodRepresentante(CodRep);
Random rand = new Random();
int randomNum = rand.nextInt((1500 - 500) + 1) + 500;
try {
Thread.sleep(randomNum);
} catch (InterruptedException ex) {
Logger.getLogger(Teste1WS.class.getName()).log(Level.SEVERE, null, ex);
}
return RetWS1;
}
}