• Post Reply Bookmark Topic Watch Topic
  • New Topic

ScheduledExecutorService + scheduleWithFixedDelay() with Task throws exception  RSS feed

 
kri shan
Ranch Hand
Posts: 1487
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@WebListener
public class BackgroundJobManager implements ServletContextListener {
Scheduler not runs after MyTask throws Exception. How to run the Scheduler continuously even though SomeTask() throws Exception.




}
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do you still want to run thread even after exception? Generally, exception is a situation where program doesn't perform expected operation.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not all exceptions are fatal. Often, an error condition may be recoverable at a later point of time or may be localized one.
If a thread has the task of processing a thousands of files coming in, and file #453 has some encoding error, it doesn't warrant stopping all processing of every other subsequent file.

Kri Shan, inside your task, catch exceptions, log them somewhere at a minimum, and for recoverable errors, either retry immediately a limited number of times or consider resubmitting the task to executor for processing later on.
 
kri shan
Ranch Hand
Posts: 1487
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How to retry immediately limited number of times or resubmitting the task 'thread' to executor for later processing.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a loop and resubmit it the same way you submitted it the first time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!