Salve a tutti,
sto progettando una servlet che utilizza dei file,
questi vengono letti all'apertura (nel metodo init() ) ed i dati presi e memorizzati su un database;
i dati possono nel frattempo essere modificati sul db e vorrei, a questo punto, che quando la servlet termina il servizio/si stoppa il server i dati del database vengano salvati su dei file.
Ho provato a mettere nel metodo destroy() la chiamata ad un metodo della classe che gestisce il db e che dovrebbe fare questo, ma quando stoppo il server (uso eclipse per java ee) non succede nulla ed i file non sono aggiornati.
questo è il metodo nella servlet:
codice:
public void destroy() { // ---> non viene chiamato !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
System.out.println("sono nel destroy");
FileOutputStream fosCalendarioA = null, fosCalendarioB = null, fosCalendario1A = null;
FileOutputStream fosCalendario1B = null, fosCalendario2A = null, fosCalendario2B = null;
try {
fosCalendarioA = new FileOutputStream("/WEB-INF/File_del_Server/Calendario_A_1314.txt", true);
fosCalendarioB = new FileOutputStream("/WEB-INF/File_del_Server/Calendario_B_1314.txt", true); // throws FileNotFoundException
fosCalendario1A = new FileOutputStream("/WEB-INF/File_del_Server/Calendario_1A_1314.txt", true); // throws FileNotFoundException
fosCalendario1B = new FileOutputStream("/WEB-INF/File_del_Server/Calendario_1B_1314.txt", true); // throws FileNotFoundException
fosCalendario2A = new FileOutputStream("/WEB-INF/File_del_Server/Calendario_2A_1314.txt", true); // throws FileNotFoundException
fosCalendario2B = new FileOutputStream("/WEB-INF/File_del_Server/Calendario_2B_1314.txt", true); // throws FileNotFoundException
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
synchronized (servletContext){
boolean esitoChiusura = DbHandler.salvaNeiFile(fosCalendarioA, fosCalendarioB, fosCalendario1A, fosCalendario1B, fosCalendario2A, fosCalendario2B);
if(esitoChiusura) System.out.println("Salvataggio sui file eseguito");
else System.out.println("Salvataggio sui file non eseguito");
}
}
la scritta "sono nel destroy" non viene visualizzata dopo che premo stop sul server, sbaglio qualcosa?