FileDocCategorySizeDatePackage
AutoSave.javaAPI DocExample657Sun Dec 27 15:20:28 GMT 1998None

AutoSave.java

// $Id: AutoSave.java,v 1.1.1.1 1998/12/27 20:20:28 ian Exp $
public class AutoSave extends Thread {
	FileSaver model;

	public AutoSave(FileSaver m) {
		super("AutoSave Thread");
		setDaemon(true);		// so we don't keep the main app alive
		model = m;
	}

	public void run() {
		while (true) {		// entire run method runs forever.
			try {
				sleep(30*1000);
			} catch (InterruptedException e) {
				// do nothing with it
			}
			if (model.wantAutoSave() && model.hasUnsavedChanges())
				model.saveFile(null);
		}
	}

	// Not shown:
	// 1) saveFile() must now be synchronized.
	// 2) method that shuts down main program be synchronized on *SAME* object
}