I have a servlet which accesses and modifies an object "myBean" stored in a servlet context. Is explicitly locking "myBean" with a synchronized block needed or it is maintained by default? Example code:
public class StopFilesMergeServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
MYBean myBean = req.getServletContext().getAttribute("myBean");
synchronized (myBean) { //is this necessary?
int oldValue = myBean.getProperty1();
int newValue = oldValue + 10;
myBean.setProperty1(newValue);
}
...
return;
}