当前位置: 首页>>代码示例>>Java>>正文


Java TimerTask类代码示例

本文整理汇总了Java中java.util.TimerTask的典型用法代码示例。如果您正苦于以下问题:Java TimerTask类的具体用法?Java TimerTask怎么用?Java TimerTask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TimerTask类属于java.util包,在下文中一共展示了TimerTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startItem

import java.util.TimerTask; //导入依赖的package包/类
@Override
protected void startItem(PlayableItem playableItem, Object loadedItem) {
    // Communicating with the activity is only possible after the activity
    // is started
    // if we send an broadcast event to early the activity won't be up
    // because there is no known way to query the activity state
    // we are sending the command delayed
    DIDLObject.Property<URI> albumArtUriProperty = playableItem.getItem() == null ? null : playableItem.getItem().getFirstProperty(DIDLObject.Property.UPNP.ALBUM_ART_URI.class);
    albumArtUri = (albumArtUriProperty == null) ? null : albumArtUriProperty.getValue();

    commandExecutionTimer = new Timer();
    commandExecutionTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            Intent intent = new Intent();
            intent.setAction(BackgroundMusicBroadcastReceiver.ACTION_PLAY);
            getContext().sendBroadcast(intent);
        }
    }, 600L);
}
 
开发者ID:theopenbit,项目名称:yaacc-code,代码行数:22,代码来源:LocalBackgoundMusicPlayer.java

示例2: timerOne

import java.util.TimerTask; //导入依赖的package包/类
public void timerOne()
{
    timer.schedule(new TimerTask()
    {
        @Override
        public void run()
        {
            System.out.println("timerOne invoked ,the time:"
                    + (System.currentTimeMillis() - start));
            try
            {
                Thread.sleep(4000);
            } catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }, 1000);
}
 
开发者ID:baohongfei,项目名称:think-in-java,代码行数:20,代码来源:TimerTest04.java

示例3: SpongeStats

import java.util.TimerTask; //导入依赖的package包/类
public SpongeStats(MCMarketApi marketApi, PluginContainer plugin) {
    super(marketApi);

    Sponge.getEventManager().registerListeners(plugin, this);

    Timer timer = new Timer(true);
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            if (!Sponge.getPluginManager().isLoaded(plugin.getId())) {
                timer.cancel();
                return;
            }

            Sponge.getScheduler().createTaskBuilder().execute(() -> runEventsSender()).submit(plugin);
        }
    }, 1000 * 10, 1000 * 60);
}
 
开发者ID:MinecraftMarket,项目名称:MinecraftMarket-Plugin,代码行数:20,代码来源:SpongeStats.java

示例4: put

import java.util.TimerTask; //导入依赖的package包/类
public void put(MyElement<K, V> element) {
    if (elements.size() == maxElements) {
        K firstKey = elements.keySet().iterator().next();
        elements.remove(firstKey);
    }

    K key = element.getKey();
    elements.put(key, element);

    if (!isEternal) {
        if (lifeTimeMs != 0) {
            TimerTask lifeTimerTask = getTimerTask(key, lifeElement -> lifeElement.getCreationTime() + lifeTimeMs);
            timer.schedule(lifeTimerTask, lifeTimeMs);
        }
        if (idleTimeMs != 0) {
            TimerTask idleTimerTask = getTimerTask(key, idleElement -> idleElement.getLastAccessTime() + idleTimeMs);
            timer.schedule(idleTimerTask, idleTimeMs, idleTimeMs);
        }
    }
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_10,代码行数:21,代码来源:CacheEngineImpl.java

示例5: submit

import java.util.TimerTask; //导入依赖的package包/类
public synchronized void submit(final RunnableFuture task, long delay)
{
   getTimer().schedule(new TimerTask()
      {
         @Override
         public void run()
         {
            Thread t = new Thread(new Runnable()
               {
                  @Override
                  public void run()
                  {
                     submit(task);
                  }
               });
            t.setDaemon(daemon);
            t.start();
         }
      }, delay);
}
 
开发者ID:wellsb1,项目名称:fort_j,代码行数:21,代码来源:Executor.java

示例6: startSubmitting

import java.util.TimerTask; //导入依赖的package包/类
/**
 * Starts the Scheduler which submits our data every 30 minutes.
 */
private void startSubmitting() {
    final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            if (!plugin.isEnabled()) { // Plugin was disabled
                timer.cancel();
                return;
            }
            // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
            // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
            Bukkit.getScheduler().runTask(plugin, new Runnable() {
                @Override
                public void run() {
                    submitData();
                }
            });
        }
    }, 1000*60*5, 1000*60*30);
    // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
    // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
    // WARNING: Just don't do it!
}
 
开发者ID:WheezyGold7931,项目名称:Anti-Rooktube,代码行数:27,代码来源:Metrics.java

示例7: sendTimeUpdates

import java.util.TimerTask; //导入依赖的package包/类
/**
 * Start sending time events to listeners.
 * @param playerIndex Player index to send times for
 */
private void sendTimeUpdates(int playerIndex) {
    this.timeUpdateSender = new TimerTask() {
        long startTime = System.currentTimeMillis();
        long moveTime = settings.getMoveTimeMillis();
        long gameTime = times[playerIndex - 1];
        @Override
        public void run() {
            long elapsed = System.currentTimeMillis() - startTime;
            gameTime -= elapsed;
            moveTime -= elapsed;
            // Broadcast the elapsed times since the last TimerTask
            if(settings.gameTimingEnabled()) {
                listeners.forEach(listener -> listener.gameTimeChanged
                        (playerIndex, gameTime));
            }
            if(settings.moveTimingEnabled()) {
                listeners.forEach(listener -> listener.moveTimeChanged
                        (playerIndex, moveTime));
            }
            startTime = System.currentTimeMillis();
        }
    };
    timer.scheduleAtFixedRate(timeUpdateSender, 0, 100);
}
 
开发者ID:haslam22,项目名称:gomoku,代码行数:29,代码来源:Game.java

示例8: main

import java.util.TimerTask; //导入依赖的package包/类
public static void main(String []s)
{
    final Dialog fd = new Dialog(new Frame(), true);
    Timer t = new Timer();
    t.schedule(new TimerTask() {

        public void run() {
            System.out.println("RUNNING TASK");
            fd.setVisible(false);
            fd.dispose();
            System.out.println("FINISHING TASK");
        }
    }, 3000L);

    fd.setVisible(true);
    t.cancel();
    Util.waitForIdle(null);

    AbstractTest.pass();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:CrashXCheckJni.java

示例9: runQuery

import java.util.TimerTask; //导入依赖的package包/类
public static Thread runQuery(final String query,
                              final Consumer<Boolean> success,
                              final Consumer<BackendException> failure,
                              final long timeout) {

    final Consumer<Engine> engineConsumer = engine -> {
        if(timeout >= 0) {
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    synchronized (engineLock) {
                        if(engine == null) return;
                        engine.cancel();
                    }
                }
            }, timeout);
        }
    };

    return runQuery(query, success, failure, engineConsumer);
}
 
开发者ID:ulriknyman,项目名称:H-Uppaal,代码行数:22,代码来源:UPPAALDriver.java

示例10: startMp4

import java.util.TimerTask; //导入依赖的package包/类
public void startMp4(File f) {
    mVideoFragment = VideoFragment.newInstance(f.getPath(), true);
    transaction.add(R.id.init_frame, mVideoFragment, "initVideo").commit();
    exitTimer = new Timer();
    exitTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            videoTime--;
            InitStartActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (exitInit != null) {
                        exitInit.setText(mWeApplication.getResources().getString(R.string.exit_init) + videoTime);
                        if (videoTime <= 0) {
                            HomeActivity.show(InitStartActivity.this);
                            InitStartActivity.this.finish();
                        }
                    }
                }
            });

        }
    }, 0, 1 * 1000);
}
 
开发者ID:snowwolf10285,项目名称:PicShow-zhaipin,代码行数:25,代码来源:InitStartActivity.java

示例11: fadeOut

import java.util.TimerTask; //导入依赖的package包/类
private void fadeOut() {
    cancelFadeTasks();

    if (musicPlayer != null && volume > 0.1f) {
        fadeOutTask = new TimerTask() {
            @Override
            public void run() {
                if (musicPlayer != null) {
                    volume -= 0.1f;
                    if (volume < 0.1f) {
                        cancel();
                    }

                    try {
                        musicPlayer.setVolume(volume, volume);
                    } catch (IllegalStateException e) {
                        e.printStackTrace();
                    }
                }
            }
        };

        timer.schedule(fadeOutTask, 0, 100);
    }
}
 
开发者ID:Dentacoin,项目名称:aftercare-app-android,代码行数:26,代码来源:DCSoundManager.java

示例12: fadeIn

import java.util.TimerTask; //导入依赖的package包/类
private void fadeIn() {
    cancelFadeTasks();

    if (musicPlayer != null && volume < 0.9f) {
        fadeInTask = new TimerTask() {
            @Override
            public void run() {
                if (musicPlayer != null) {
                    volume += 0.1f;
                    if (volume > 0.9f) {
                        cancel();
                    }

                    try {
                        musicPlayer.setVolume(volume, volume);
                    } catch (IllegalStateException e) {
                        e.printStackTrace();
                    }
                }
            }
        };

        timer.schedule(fadeInTask, 0, 100);
    }
}
 
开发者ID:Dentacoin,项目名称:aftercare-app-android,代码行数:26,代码来源:DCSoundManager.java

示例13: onFinish

import java.util.TimerTask; //导入依赖的package包/类
@Override
public void onFinish() {
    // 如果计时器正常结束,则开始计步
    time.cancel();
    StepSensorBase.CURRENT_STEP += TEMP_STEP;
    lastStep = -1;
    Log.v(TAG, "计时正常结束");

    timer = new Timer(true);
    TimerTask task = new TimerTask() {
        public void run() {
            if (lastStep == StepSensorBase.CURRENT_STEP) {
                timer.cancel();
                CountTimeState = 0;
                lastStep = -1;
                TEMP_STEP = 0;
                Log.v(TAG, "停止计步:" + StepSensorBase.CURRENT_STEP);
            } else {
                lastStep = StepSensorBase.CURRENT_STEP;
            }
        }
    };
    timer.schedule(task, 0, 2000);
    CountTimeState = 2;
}
 
开发者ID:SailFlorve,项目名称:RunHDU,代码行数:26,代码来源:StepSensorAcceleration.java

示例14: Batcher

import java.util.TimerTask; //导入依赖的package包/类
public Batcher(BatchedAction<T> action, long interval, final Handler handler){
    this.interval = interval;
    
    if (handler != null)
        this.handler = new WeakReference<Handler>(handler);

    timerTask = new TimerTask() {
        @Override
        public void run() {
            if (pulled && !toHold())
            {
                trigger();
            }
        }
    };

    timer.scheduleAtFixedRate(timerTask, this.interval, this.interval);

    setBatchedAction(action);
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:21,代码来源:Batcher.java

示例15: stopItem

import java.util.TimerTask; //导入依赖的package包/类
@Override
protected void stopItem(PlayableItem playableItem) {

    // Communicating with the activity is only possible after the activity
    // is started
    // if we send an broadcast event to early the activity won't be up
    // because there is no known way to query the activity state
    // we are sending the command delayed
    commandExecutionTimer = new Timer();
    commandExecutionTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            Intent intent = new Intent();
            intent.setAction(BackgroundMusicBroadcastReceiver.ACTION_STOP);
            getContext().sendBroadcast(intent);

        }
    }, 600L);
}
 
开发者ID:theopenbit,项目名称:yaacc-code,代码行数:21,代码来源:LocalBackgoundMusicPlayer.java


注:本文中的java.util.TimerTask类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。