移動開發---ScheduledExecutorService定時任務

//每6小時彈出請求網絡策略
		ScheduledExecutorService scheduledExecutorService =  Executors.newScheduledThreadPool(1);
		scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
			@Override
			public void run() {
					Log.e("ScheduledExecutor","ScheduledExecutor");
				if (Utils.isNetWorkAvaiable(SupportService.this)) {
				       //執行操作
				}
			}
		},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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章