I'm working on a web application in which a servlet named CheckURL will read some data from a xml file in its init method and will put the node list from this xml in the servletcontext. So every request coming to this servlet would not have to read data from the xml again and again. It could just get the node list from the servletcontext. There is a another servlet in the application which is used to update the xml and I will update the servletcontext nodelist variable if xml is updated.
So in this scenario, I would like to have synchronization in place to make sure that, when writing to the xml happens, any reading from the servletcontext nodelist should be blocked. If not it might be reading data which is not up to date.
To achieve this, I am wondering which synchronization level should I be using. Should I synchronize on servletcontext object or should I be synchronizing on the element set in the servlet context or should I be synchronizing on the servlet class instance.