Search in sources :

Example 16 with TimerTask

use of java.util.TimerTask in project tomcat by apache.

the class PoolUtils method checkMinIdle.

/**
     * Periodically check the idle object count for each key in the
     * <code>Collection</code> <code>keys</code> in the keyedPool. At most one
     * idle object will be added per period.
     *
     * @param keyedPool
     *            the keyedPool to check periodically.
     * @param keys
     *            a collection of keys to check the idle object count.
     * @param minIdle
     *            if the {@link KeyedObjectPool#getNumIdle(Object)} is less than
     *            this then add an idle object.
     * @param period
     *            the frequency to check the number of idle objects in a
     *            keyedPool, see {@link Timer#schedule(TimerTask, long, long)}.
     * @param <K> the type of the pool key
     * @param <V> the type of pool entries
     * @return a {@link Map} of key and {@link TimerTask} pairs that will
     *         periodically check the pools idle object count.
     * @throws IllegalArgumentException
     *             when <code>keyedPool</code>, <code>keys</code>, or any of the
     *             values in the collection is <code>null</code> or when
     *             <code>minIdle</code> is negative or when <code>period</code>
     *             isn't valid for {@link Timer#schedule(TimerTask, long, long)}
     *             .
     * @see #checkMinIdle(KeyedObjectPool, Object, int, long)
     */
public static <K, V> Map<K, TimerTask> checkMinIdle(final KeyedObjectPool<K, V> keyedPool, final Collection<K> keys, final int minIdle, final long period) throws IllegalArgumentException {
    if (keys == null) {
        throw new IllegalArgumentException("keys must not be null.");
    }
    final Map<K, TimerTask> tasks = new HashMap<>(keys.size());
    final Iterator<K> iter = keys.iterator();
    while (iter.hasNext()) {
        final K key = iter.next();
        final TimerTask task = checkMinIdle(keyedPool, key, minIdle, period);
        tasks.put(key, task);
    }
    return tasks;
}
Also used : TimerTask(java.util.TimerTask) HashMap(java.util.HashMap)

Example 17 with TimerTask

use of java.util.TimerTask in project tomcat by apache.

the class PoolUtils method checkMinIdle.

/**
     * Periodically check the idle object count for the key in the keyedPool. At
     * most one idle object will be added per period. If there is an exception
     * when calling {@link KeyedObjectPool#addObject(Object)} then no more
     * checks for that key will be performed.
     *
     * @param keyedPool
     *            the keyedPool to check periodically.
     * @param key
     *            the key to check the idle count of.
     * @param minIdle
     *            if the {@link KeyedObjectPool#getNumIdle(Object)} is less than
     *            this then add an idle object.
     * @param period
     *            the frequency to check the number of idle objects in a
     *            keyedPool, see {@link Timer#schedule(TimerTask, long, long)}.
     * @param <K> the type of the pool key
     * @param <V> the type of pool entries
     * @return the {@link TimerTask} that will periodically check the pools idle
     *         object count.
     * @throws IllegalArgumentException
     *             when <code>keyedPool</code>, <code>key</code> is
     *             <code>null</code> or when <code>minIdle</code> is negative or
     *             when <code>period</code> isn't valid for
     *             {@link Timer#schedule(TimerTask, long, long)}.
     */
public static <K, V> TimerTask checkMinIdle(final KeyedObjectPool<K, V> keyedPool, final K key, final int minIdle, final long period) throws IllegalArgumentException {
    if (keyedPool == null) {
        throw new IllegalArgumentException("keyedPool must not be null.");
    }
    if (key == null) {
        throw new IllegalArgumentException("key must not be null.");
    }
    if (minIdle < 0) {
        throw new IllegalArgumentException("minIdle must be non-negative.");
    }
    final TimerTask task = new KeyedObjectPoolMinIdleTimerTask<>(keyedPool, key, minIdle);
    getMinIdleTimer().schedule(task, 0L, period);
    return task;
}
Also used : TimerTask(java.util.TimerTask)

Example 18 with TimerTask

use of java.util.TimerTask in project UltimateAndroid by cymcsg.

the class CircleProgressActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.circle_progress_activity_my);
    donutProgress = (DonutProgress) findViewById(R.id.donut_progress);
    circleProgress = (CircleProgress) findViewById(R.id.circle_progress);
    arcProgress = (ArcProgress) findViewById(R.id.arc_progress);
    timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    donutProgress.setProgress(donutProgress.getProgress() + 1);
                    circleProgress.setProgress(circleProgress.getProgress() + 1);
                    arcProgress.setProgress(arcProgress.getProgress() + 1);
                }
            });
        }
    }, 1000, 100);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 19 with TimerTask

use of java.util.TimerTask in project PlayerHater by chrisrhoden.

the class PlaylistSupportingPlayer method startWithFade.

public void startWithFade() throws IllegalStateException {
    setVolume(0, 0);
    start();
    final Timer timer = new Timer(true);
    TimerTask timerTask = new TimerTask() {

        @Override
        public void run() {
            setVolume(mLeftVolume + 0.1f, mRightVolume + 01.f);
            if (mLeftVolume >= 1.0f || mRightVolume >= 1.0f) {
                timer.cancel();
                timer.purge();
            }
        }
    };
    timer.schedule(timerTask, 200, 200);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 20 with TimerTask

use of java.util.TimerTask in project AnimeTaste by daimajia.

the class StartActivity method showWhatsNew.

public void showWhatsNew() {
    boolean showed = mSharedPreferences.getBoolean("showed15", false);
    if (!showed) {
        Toast.makeText(mContext, R.string.intro_drawer, Toast.LENGTH_SHORT).show();
        mDrawerLayout.openDrawer(mDrawerLayout.getChildAt(1));
        new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        mDrawerLayout.closeDrawers();
                    }
                });
                mSharedPreferences.edit().putBoolean("showed15", true).commit();
            }
        }, 3000);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Aggregations

TimerTask (java.util.TimerTask)359 Timer (java.util.Timer)260 IOException (java.io.IOException)25 Date (java.util.Date)21 Test (org.junit.Test)20 File (java.io.File)13 ArrayList (java.util.ArrayList)11 Intent (android.content.Intent)8 Bundle (android.os.Bundle)8 InputMethodManager (android.view.inputmethod.InputMethodManager)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Location (android.location.Location)6 LocationListener (android.location.LocationListener)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 TextView (android.widget.TextView)5 URI (java.net.URI)5 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5