Incrementing member variable in Synchronized block
Hi,
The following is the code block:
public class MyThreads extends HttpServlet{
private String postCountLock = "postCountLock";
private int postCount = 0;
public void doPost(HttpServletRequest req,HttpServletResponse res) throws Exception{
int localPostCount=0;
synchronized(postCountLock){
postCount++;
localPostCount=postCount;
}
}
}
Here I want to know whether the member variable 'postCount' is thread safe or not?
Thanks in advance for your help.
|