Search in sources :

Example 66 with TimerTask

use of java.util.TimerTask in project AndroidTraining by mixi-inc.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final Handler handler = new Handler();
    final Timer timer = new Timer();
    // 5秒ごとにレベルを変更するタスク
    final Drawable levelListDrawable = findViewById(R.id.LevelListButton).getBackground();
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            final int level = levelListDrawable.getLevel();
            handler.post(new Runnable() {

                @Override
                public void run() {
                    if (level == 0) {
                        levelListDrawable.setLevel(1);
                    } else {
                        levelListDrawable.setLevel(0);
                    }
                }
            });
        }
    }, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
    // クロスフェードを開始する
    final TransitionDrawable transition = (TransitionDrawable) findViewById(R.id.TransitionView).getBackground();
    transition.startTransition(TRANSITION_DURATION);
    // 5秒ごとにレベルを変更し、クリップの範囲を変化させるタスク
    final ClipDrawable clipDrawable = (ClipDrawable) findViewById(R.id.ClipView).getBackground();
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            handler.post(new Runnable() {

                @Override
                public void run() {
                    clipDrawable.setLevel(clipDrawable.getLevel() + 1000);
                }
            });
        }
    }, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
    // スケールのレベルを変更する
    ScaleDrawable scale = (ScaleDrawable) findViewById(R.id.ScaleView).getBackground();
    scale.setLevel(1);
}
Also used : ScaleDrawable(android.graphics.drawable.ScaleDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Timer(java.util.Timer) TimerTask(java.util.TimerTask) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) Drawable(android.graphics.drawable.Drawable) ScaleDrawable(android.graphics.drawable.ScaleDrawable) Handler(android.os.Handler) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 67 with TimerTask

use of java.util.TimerTask in project ACS by ACS-Community.

the class GCJMXClient method main.

public static void main(String[] args) {
    if (args.length < 2) {
        System.err.println("Must provide 2 arguments: <classname> <interval-in-ms>");
    }
    final GCJMXClient client = new GCJMXClient(args[0]);
    try {
        client.connect();
    } catch (Exception e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    ObjectName objName = null;
    try {
        objName = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
    } catch (MalformedObjectNameException e1) {
        System.err.println("bad name?");
        System.exit(1);
    }
    final ObjectName objNameF = objName;
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {

        public void run() {
            MBeanServerConnection con = client.getRemote();
            try {
                con.invoke(objNameF, "gc", null, null);
                System.out.println("Called gc() on remote VM");
            } catch (Exception e) {
                System.err.println("Couldn't call gc() on remote VM");
            }
        }
    };
    timer.scheduleAtFixedRate(task, new Date(), Integer.parseInt(args[1]));
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanServerConnection(javax.management.MBeanServerConnection) Date(java.util.Date) ObjectName(javax.management.ObjectName)

Example 68 with TimerTask

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

the class SliderLayout method recoverCycle.

/**
     * when paused cycle, this method can weak it up.
     */
private void recoverCycle() {
    if (!mAutoRecover || !mAutoCycle) {
        return;
    }
    if (!mCycling) {
        if (mResumingTask != null && mResumingTimer != null) {
            mResumingTimer.cancel();
            mResumingTask.cancel();
        }
        mResumingTimer = new Timer();
        mResumingTask = new TimerTask() {

            @Override
            public void run() {
                startAutoCycle();
            }
        };
        mResumingTimer.schedule(mResumingTask, 6000);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 69 with TimerTask

use of java.util.TimerTask in project EnrichmentMapApp by BaderLab.

the class ComputeSimilarityTaskParallel method run.

@Override
public void run(TaskMonitor tm) throws InterruptedException {
    int cpus = Runtime.getRuntime().availableProcessors();
    ExecutorService executor = Executors.newFixedThreadPool(cpus);
    boolean distinct = map.getParams().getCreateDistinctEdges();
    Map<SimilarityKey, GenesetSimilarity> similarities = startComputeSimilarities(tm, executor, distinct, !distinct);
    // Support cancellation
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {

        public void run() {
            if (cancelled) {
                executor.shutdownNow();
            }
        }
    }, 0, 1000);
    executor.shutdown();
    executor.awaitTermination(3, TimeUnit.HOURS);
    timer.cancel();
    if (!cancelled)
        consumer.accept(similarities);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) ExecutorService(java.util.concurrent.ExecutorService) SimilarityKey(org.baderlab.csplugins.enrichmentmap.model.SimilarityKey) GenesetSimilarity(org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity)

Example 70 with TimerTask

use of java.util.TimerTask in project cubrid-manager by CUBRID.

the class QuickBuilderDialog method startTimerForUpdateProposal.

private void startTimerForUpdateProposal() {
    TimerTask proposalUpdateNotifyTask = new TimerTask() {

        public void run() {
            ColumnProposal proposalTemp = ColumnProposalAdvisor.getInstance().findProposal(databaseInfo);
            if (proposalTemp == null) {
                return;
            }
            if (proposalUpdateTimer != null) {
                proposalUpdateTimer.cancel();
                proposalUpdateTimer = null;
            }
            proposal = proposalTemp;
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    if (updateNoticeBanner != null) {
                        updateNoticeBanner.dispose();
                        updateNoticeBanner = null;
                    }
                    if (searchView != null) {
                        searchView.setInput(proposal);
                    }
                    shell.layout(true, true);
                }
            });
        }
    };
    proposalUpdateTimer = new Timer(true);
    proposalUpdateTimer.schedule(proposalUpdateNotifyTask, 500);
}
Also used : TimerTask(java.util.TimerTask) ColumnProposal(com.cubrid.common.ui.query.editor.ColumnProposal) Timer(java.util.Timer)

Aggregations

TimerTask (java.util.TimerTask)900 Timer (java.util.Timer)653 IOException (java.io.IOException)90 Date (java.util.Date)58 Test (org.junit.Test)57 File (java.io.File)30 ArrayList (java.util.ArrayList)29 Intent (android.content.Intent)25 AtomicLong (java.util.concurrent.atomic.AtomicLong)21 Handler (android.os.Handler)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 HashMap (java.util.HashMap)17 List (java.util.List)14 TextView (android.widget.TextView)13 CountDownLatch (java.util.concurrent.CountDownLatch)13 View (android.view.View)12 Map (java.util.Map)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 InputMethodManager (android.view.inputmethod.InputMethodManager)11 Random (java.util.Random)11