Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Service {
- private static ScheduledFuture<?> mainTask;
- public static void startService() {
- ScheduledExecutorService st = Executors.newSingleThreadScheduledExecutor();
- //Start checking for new notification
- mainTask = st.scheduleAtFixedRate(new NotificationTask(), 0, 5, TimeUnit.SECONDS);
- // Timer t = new Timer();
- // t.schedule(new NotificationTask(), 0, 5000);
- }
- static class NotificationTask extends TimerTask implements Runnable {
- private JSONObject notifications;
- private JSONObject old;
- public NotificationTask() {
- old = new JSONObject();
- }
- @Override
- public void run() {
- try {
- //Read new notification
- notifications = WebConnection.getInstance().readNotifications();
- if (!notifications.equals(old)) {
- //
- processOrderNotification();
- }
- } catch (IOException | ParseException ex) {
- //probably Network issues
- // log for debugging purposes
- Utility.writeLog(ex.toString());
- } catch (Exception e) {
- // Every other error should fall in here
- Utility.writeLog(e);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment