Reputation: 2368
A function is implemented in my Tomcat
server: basically a ScheduledExecutorService
will be setup to run a task periodically upon the initialization of a HttpServlet
. The code is like below:
@Override
public void init() throws ServletException {
HttpsTool.setupUncheckedHttps();
LOGGER.info("DeploymentInfoScheduler Initialized successfully....");
System.out.println("DeploymentInfoScheduler Initialized successfully....");
this.retrieveServiceDeploymentsInfo();
}
private void retrieveServiceDeploymentsInfo() {
final Runnable deploymentsDataHandler = new DeploymentsDataHandler();
final ScheduledFuture<?> beeperHandle = deploymentsInfoRetrieverScheduler
.scheduleAtFixedRate(deploymentsDataHandler, 0, 5, TimeUnit.MINUTES);
}
If the servlet is initialized successfully, the task will keep running every 5 seconds forever. In the DeploymentsDataHandler
's run
method, A message is logged like below at the very beginning:
@Override
public void run() {
LOGGER.info("Now begin a new round of refreshing deployment data...");
this.doWorkFlow();
}
Correct me if I am wrong: no matter whether there is any exception unhandled in the doWorkFlow
method, that message should always be logged every 5 minutes. But the fact is this scheduler runs well for some time and suddenly stops working, and even the message is stopped to be logged. Any possible explanation? How could I handle such an situation since I want to make sure this scheduler service is always running. Or is there any way to debug this issue?
I assume the following code will make sure the Scheduler
will never stop executing even an exception occurs in the doworkFlow
.
@Override
public void run() {
try{
LOGGER.info("Now begin a new round of refreshing deployment data...");
this.doWorkFlow();
}catch(Exception e){
return;
}
}
Upvotes: 0
Views: 557
Reputation: 691635
Correct me if I am wrong: no matter whether there is any exception unhandled in the doWorkFlow method, that message should always be logged every 5 minutes
No, since the javadoc explicitly says:
If any execution of the task encounters an exception, subsequent executions are suppressed
Upvotes: 2