java - How to perform a Differential Sync between a collection of objects and a DB Table -
i have hashmap of type (string, pojoobj). used java program running , triggered using quartz schedular @ regular intervals.
for safety during abrupt killing of java process.. hashmap destroyed.. making loss of data..
so, planning dump/sync hashmap data ( pojo objects ) when class started executing schedular. effective if sync differential.. ( changed values updated in db ).
i dont have idea it... please me.. using hibernate 3.5 in program.
you can use shutdown handler purpose :
public final class myshutdownhandler extends thread { private list<iobserver> observerlist; private static myshutdownhandler shutdownhandler; private myshutdownhandler() { observerlist = new arraylist<iobserver>(); runtime.getruntime().addshutdownhook(this); } public static myshutdownhandler getshutdownhandler() { if (shutdownhandler == null) { synchronized (myshutdownhandler.class) { if (shutdownhandler == null) { shutdownhandler = new myshutdownhandler(); } } } return shutdownhandler; } public void run() { (iobserver observer : observerlist) { observer.execute(); } } public void register(iobserver observer) { observerlist.add(observer); } }
you can register many observers (implementations of iobserver) need. particular observer can necessary processes before shutdown happens.
public interface iobserver { void execute(); }
Comments
Post a Comment