当前位置:   article > 正文

移动开发---ScheduledExecutorService定时任务_移动端定时任务

移动端定时任务
  1. //每6小时弹出請求网络策略
  2. ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
  3. scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
  4. @Override
  5. public void run() {
  6. Log.e("ScheduledExecutor","ScheduledExecutor");
  7. if (Utils.isNetWorkAvaiable(SupportService.this)) {
  8. //执行操作
  9. }
  10. }
  11. },6,6,TimeUnit.HOURS);
 *
 * @param command the task to execute
 * @param initialDelay the time to delay first execution
 * @param period the period between successive executions
 * @param unit the time unit of the initialDelay and period parameters
 * @return a ScheduledFuture representing pending completion of
 *         the series of repeated tasks.  The future's {@link
 *         Future#get() get()} method will never return normally,
 *         and will throw an exception upon task cancellation or
 *         abnormal termination of a task execution.
 * @throws RejectedExecutionException if the task cannot be
 *         scheduled for execution
 * @throws NullPointerException if command is null
 * @throws IllegalArgumentException if period less than or equal to zero
 */
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
                                              long initialDelay,
                                              long period,
                                              TimeUnit unit);
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/83778
推荐阅读
  

闽ICP备14008679号