下面给出的是配置为autosys作业的url。这调用下面给出的servlet。谁能建议我如何保护这个方法“psServiceWrapper.processHRFeed();” 每次连续按下此 url 时,由于不正确的数据修改而被连续调用 10 次。我希望一次只能访问一个线程。
我知道我必须使用同步方法或块..我不确定如何..因为我不熟悉线程。
http://mydomain:11000/dorf/HRDORFScriptServlet?script=hrFeed
public class HRDORFScriptServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(HRDORFScriptServlet.class);
private final String script = "script";
@Override
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
// TODO Auto-generated method stub
performTask(arg0, arg1);
}
@Override
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
// TODO Auto-generated method stub
performTask(arg0, arg1);
}
/** Execute the servlet.
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void performTask(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {
DorfUser dorfUser = DorfSessionUtils.getDorfUser(request.getSession());
HRDorfFeedServiceWrapper psServiceWrapper = new HRDorfFeedServiceWrapper(dorfUser);
String reqParam = request.getParameter(script);
if(reqParam.equals("hrFeed")){
try{
psServiceWrapper.processHRFeed();
}
catch(ServiceException se){
log.error("Error While calling HRFeed Service : "+se.getMessage());
}
catch(Exception e){
log.error("Error While calling HRFeed Service : "+e.getMessage());
}
}
}
}