Skip to content

Instantly share code, notes, and snippets.

@yishai-glide
Last active August 29, 2015 14:24
Show Gist options
  • Save yishai-glide/a7e2f3d6910892d49f7c to your computer and use it in GitHub Desktop.
Save yishai-glide/a7e2f3d6910892d49f7c to your computer and use it in GitHub Desktop.
mScheduler = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread th = Executors.defaultThreadFactory().newThread(r);
th.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
th.setName("presence_thread");
return th;
}
});
HandlerThread thread = new HandlerThread("presence-parser", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mPresenceParsingHandler = new Handler(thread.getLooper());
mPresenceTask = new Runnable() {
@Override
public void run() {
//Utils.log(TAG, "mPresenceTask", 0);
try {
handlePresenceTask();
handleActionsTask();
clearAndUpdate();
} catch (Exception e) {
Utils.log(TAG, Log.getStackTraceString(e), 5);
}
}
};
mScheduleFuture = mScheduler.scheduleAtFixedRate(mPresenceTask, TIME_OF_SLEEP_CYCLE, TIME_OF_SLEEP_CYCLE, TimeUnit.SECONDS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment