Javamex

Java discussion forum to accompany the Javamex web site.

I'm working on a big codebase, and am currently implementing an autosave function. We have a root object which I can easily synchronize access to when wishing to do the save:

class App
{
private AppData data = new AppData();
private final Object lock = new Object();

public  AppData getData()
{
synchronized( lock )
{
return data;
}
}

public void setData( AppData data )
{
synchronized( lock )
{
this.data = data;
}
}














}

However we have a number of classes which have methods that cache and modify _fields_ of AppData, and so will be utterly unaware of the locking status of their parent object. What I really need is a critical section that basically makes my autosave atomic so that these other classes can't modify AppData fields (or child fields of these fields) whilst it's happening. Because the code base is so large I kinda think it would be hard to find all the places where I have to force a wait. Anyone got any suggestions?

Views: 91

Reply to This

© 2024   Created by Neil Coffey.   Powered by

Badges  |  Report an Issue  |  Terms of Service