Search in sources :

Example 41 with Timer

use of java.util.Timer in project Openfire by igniterealtime.

the class MediaProxySession method addKeepAlive.

/**
     * Add a keep alive detector.
     * If the packet still more than the keep alive delay without receiving any packets. The Session is
     * stoped and remove from agents List.
     *
     * @param delay delay time in millis to check if the channel is inactive
     */
void addKeepAlive(long delay) {
    if (idleTimer != null)
        return;
    idleTimer = new Timer();
    idleTimer.scheduleAtFixedRate(new TimerTask() {

        long lastTimeStamp = getTimestamp();

        @Override
        public void run() {
            if (lastTimeStamp == getTimestamp()) {
                stopAgent();
                return;
            }
            lastTimeStamp = getTimestamp();
        }
    }, delay, delay);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 42 with Timer

use of java.util.Timer in project Openfire by igniterealtime.

the class MediaProxySession method addLifeTime.

/**
     * Add a limited life time to the Session.
     * The Session is stoped and remove from agents List after a certain time.
     * Prevents that network cycles, refreshes a Session forever.
     *
     * @param lifetime time in Seconds to kill the Session
     */
void addLifeTime(long lifetime) {
    lifetime *= 1000;
    if (lifeTimer != null)
        return;
    lifeTimer = new Timer();
    lifeTimer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            stopAgent();
        }
    }, lifetime, lifetime);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 43 with Timer

use of java.util.Timer in project jfinal by jfinal.

the class TimeSize method start.

public void start() {
    if (!running) {
        timer = new Timer("JFinal-Scanner", true);
        task = new TimerTask() {

            public void run() {
                working();
            }
        };
        timer.schedule(task, 1010L * interval, 1010L * interval);
        running = true;
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 44 with Timer

use of java.util.Timer in project FastDev4Android by jiangqqlmj.

the class AutoGallery method start.

/**
     * 开启定时器
     */
public void start() {
    if (length > 0 && timer == null) {
        timer = new Timer();
        //进行每个delayMillis时间gallery切换一张图片
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                if (length > 0) {
                    onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
                }
            }
        }, delayMillis, delayMillis);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 45 with Timer

use of java.util.Timer in project enumerable by hraberg.

the class LambdaTest method createSingleAbstractMethodWithLibrarySuperClass.

@Test
public void createSingleAbstractMethodWithLibrarySuperClass() throws Exception {
    Timer timer = new Timer();
    int x = 0;
    TimerTask t = delegate(x = 1);
    timer.schedule(t, 50);
    assertEquals(0, x);
    sleep(100);
    assertEquals(1, x);
}
Also used : Timer(java.util.Timer) Test(org.junit.Test)

Aggregations

Timer (java.util.Timer)448 TimerTask (java.util.TimerTask)262 IOException (java.io.IOException)33 Date (java.util.Date)22 Test (org.junit.Test)15 File (java.io.File)11 ArrayList (java.util.ArrayList)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)9 Intent (android.content.Intent)8 Location (android.location.Location)8 LocationListener (android.location.LocationListener)8 Bundle (android.os.Bundle)8 ActivitiException (org.activiti.engine.ActivitiException)8 View (android.view.View)7 InputMethodManager (android.view.inputmethod.InputMethodManager)7 ImageView (android.widget.ImageView)7 BufferedReader (java.io.BufferedReader)7 InputStreamReader (java.io.InputStreamReader)7