Finally, what I did was using a Runnable inside a Service, and using a ScheduledThreadPoolExecution
, as the following way:
ScheduledThreadPoolExecutor execUpdateData = new ScheduledThreadPoolExecutor(1);
scheduledUpdateData = execUpdateData.scheduleAtFixedRate(new updateDataTask(), 0, sampling_storage_ms, TimeUnit.MILLISECONDS);