I have a lot of classes that try to write something into a database when i start my Wildfly-Server. It happens that the database is not deployed in the first place and then i get a lot of HTTPNotFound Exceptions.
Because i have a lot classes i dont wanted duplicated Code and wanted to write a helper Class "TimerHelper", where i give him for example a method and say "Try that method, if you get an exception, wait some time and try again"
Some PseudoCode:
public class TimerHelper extends TimerTask{
Object o;
public TimerHelper(Object o){
this.o = o;
}
public boolean startTask(){
try{
o.start();
}catch(Exception e){
this.wait(200);
o.start();
}
}
}
The Class that wants to write into database:
@Startup
@Singleton
public class Motor{
@PostConstruct
public void init(){
TimerHelper timer = new TimerHelper(this);
}
public void start(){
database.write("foobar");
}
}
Aucun commentaire:
Enregistrer un commentaire