Reputation:
final Runnable refresh = new Refresh(params...);
service = Executors.newScheduledThreadPool(1);
service.scheduleAtFixedRate(refresh, 0, 2000, TimeUnit.MILLISECONDS);
// OR
final Thread refresh = new Refresh(params...);
refresh.start(); // In the run() method there is a loop with a sleep of 2000 ms
Which of the above methods to repeat a piece of code are preferred and why?
Upvotes: 1
Views: 765
Reputation: 643
Upvotes: 0