开发者

use Java Swing worker as a singleton to backup application data in the background

I plan to use Java SwingWorker as a singleton to backup application data in the background periodi开发者_Go百科cally(perhaps in combination with a Swing timer or java.util.Timer)

is such a strategy sound? is applying Singleton to SwingWorker a good idea?


I don't see what SwingWorker has to do with a backup task. I don't see either what the singleton pattern has to do with. This is a task for a Timer. You might have to be careful not to start it in multiple threads however, but that should be doable without wrapping it as a singleton.


I think you could easily use the SwingWorker for saving the state of your model. If you want to do this task in the background preferably would be to make a current copy of your state and save the copy thus you do not need to worry about synchronizing the state of the model while you are saving it in another thread.

Where it goes to recovery you probably want to make sure that user will not make and later loose all that he did during the model recovery from a previous version. As on successful recovery you probably will set the current state to it. Thus in this case it is even appropriate to block any user input thus you can easily do it on the current thread. Firstly displaying some appropriate information/dialog to you user that the state is being recovered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜