Guest User

Untitled

a guest
Jan 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Exec"));
  2. [...]
  3. executor.scheduleAtFixedRate(new Runnable() {
  4.  
  5. @Override
  6. public void run() {
  7. // my task
  8. ...
  9. }, 1, 1, TimeUnit.MINUTES);
  10.  
  11. public final class ExceptionSwallowingRunnable implements Runnable {
  12. private final Runnable delegate;
  13.  
  14. public ExceptionSwallowingRunnable(Runnable delegate) {
  15. // TODO: Argument validation
  16. this.delegate = delegate;
  17. }
  18.  
  19. @Override public void run() {
  20. try {
  21. delegate.run();
  22. } catch (RuntimeException e) {
  23. // Logging etc
  24. }
  25. }
  26. }
Add Comment
Please, Sign In to add comment