Java Timer Usage schedule(final TimerTask task, final int delay, final int period)

Here you can find the source of schedule(final TimerTask task, final int delay, final int period)

Description

schedule

License

Open Source License

Declaration

public synchronized static void schedule(final TimerTask task, final int delay, final int period) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2013 compeople AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w  w  w. jav a2s . c om*/
 *    compeople AG - initial API and implementation
 *******************************************************************************/

import java.util.HashSet;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;

public class Main {
    private final static Timer TIMER = new Timer();
    private static Set<TimerTask> tasks = new HashSet<TimerTask>();

    public synchronized static void schedule(final TimerTask task, final int delay, final int period) {
        if (tasks.contains(task)) {
            return;
        }
        // the actual task of work
        TIMER.schedule(task, delay, period);

        tasks.add(task);
    }
}

Related

  1. getSlowTimer()
  2. getTimer(String id)
  3. mayNewTasksBeScheduled(Timer timer)
  4. printLoadToConsole(int milliOffset)
  5. runRotateKeys()
  6. schedule(TimerTask task, long delay, long period, String name)
  7. startTimerWithDelayInMillis(TimerTask task, long millisToDelay, long intervalInMillis)
  8. stop(final TimerTask task)
  9. stopPrintStackTraces()