I have servlet printingServlet
and have two Global variables linesPrinted
and pages
public class printingServlet extends HttpServlet {
int linesPrinted = -3;
int pages = 0;
----
----
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//print some lines
//increment linesPrinted and pages
//call function2,function3,function4,Checkfunction
}
public void function1(){
//print some lines
// increment linesPrinted and pages
//call Checkfunction
}
public void function2(){
//print some lines
// increment linesPrinted and pages
//call Checkfunction
}
public void function3(){
//print some lines
// increment linesPrinted and pages
//call Checkfunction
}
public void Checkfunction(){
// check linesPrinted and pages
// Do some stuff if specific values are reached else continue
}
all @override methods
}
This works fine when only one user calls this servlet
, but lately it shows some problems in page and lines calculation when requests are concurrently sent to the servlet
.
When the request that created error is requested without any concurrent requests then it works fine.
What should be done to avoid such a problem?