本文整理匯總了Java中java.util.Timer.scheduleAtFixedRate方法的典型用法代碼示例。如果您正苦於以下問題:Java Timer.scheduleAtFixedRate方法的具體用法?Java Timer.scheduleAtFixedRate怎麽用?Java Timer.scheduleAtFixedRate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Timer
的用法示例。
在下文中一共展示了Timer.scheduleAtFixedRate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onLocationChanged
import java.util.Timer; //導入方法依賴的package包/類
@Override
public void onLocationChanged(Location location) {
// save for later analysis
gpx.appendData(location);
// for display during tracking and calculating of averages on the device
if(lastLoc == null){
lastLoc = location;
}
++numberOfPoints;
speedSum += location.getSpeed();
distance += location.distanceTo(lastLoc);
lastLoc = location;
if(firstLocation) {
// now that we have our first data point, we can update the GUI without throwing a NullPointerException
firstLocation = false;
Timer timer = new Timer();
timer.scheduleAtFixedRate(updateInterfaceTask, 0, 1000);
}
}
示例2: scheduleNow
import java.util.Timer; //導入方法依賴的package包/類
void scheduleNow(Timer timer, TimerTask task, int how) {
switch (how) {
case 0 :
timer.schedule(task, new Date(), Long.MAX_VALUE);
break;
case 1:
timer.schedule(task, 0L, Long.MAX_VALUE);
break;
case 2:
timer.scheduleAtFixedRate(task, new Date(), Long.MAX_VALUE);
break;
case 3:
timer.scheduleAtFixedRate(task, 0L, Long.MAX_VALUE);
break;
default:
fail(String.valueOf(how));
}
}
示例3: serviceStart
import java.util.Timer; //導入方法依賴的package包/類
/**
* Method used to start the disk health monitoring, if enabled.
*/
@Override
protected void serviceStart() throws Exception {
if (isDiskHealthCheckerEnabled) {
dirsHandlerScheduler = new Timer("DiskHealthMonitor-Timer", true);
dirsHandlerScheduler.scheduleAtFixedRate(monitoringTimerTask,
diskHealthCheckInterval, diskHealthCheckInterval);
}
super.serviceStart();
}
示例4: startSubmitting
import java.util.Timer; //導入方法依賴的package包/類
private void startSubmitting() {
// We use a timer cause want to be independent from the server tps
final Timer timer = new Timer(true);
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// Plugin was disabled, e.g. because of a reload (is this even possible in Sponge?)
if (!Sponge.getPluginManager().isLoaded(plugin.getId())) {
timer.cancel();
return;
}
// The data collection (e.g. for custom graphs) is done sync
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Scheduler scheduler = Sponge.getScheduler();
Task.Builder taskBuilder = scheduler.createTaskBuilder();
taskBuilder.execute(() -> submitData()).submit(plugin);
}
}, 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!
}
示例5: startSubmitting
import java.util.Timer; //導入方法依賴的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() {
// 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 ;)
FMLCommonHandler.instance().getMinecraftServerInstance().processQueue.add(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!
}
示例6: DecayRpcScheduler
import java.util.Timer; //導入方法依賴的package包/類
/**
* Create a decay scheduler.
* @param numQueues number of queues to schedule for
* @param ns config prefix, so that we can configure multiple schedulers
* in a single instance.
* @param conf configuration to use.
*/
public DecayRpcScheduler(int numQueues, String ns, Configuration conf) {
if (numQueues < 1) {
throw new IllegalArgumentException("number of queues must be > 0");
}
this.numQueues = numQueues;
this.decayFactor = parseDecayFactor(ns, conf);
this.decayPeriodMillis = parseDecayPeriodMillis(ns, conf);
this.identityProvider = this.parseIdentityProvider(ns, conf);
this.thresholds = parseThresholds(ns, conf, numQueues);
// Setup delay timer
Timer timer = new Timer();
DecayTask task = new DecayTask(this, timer);
timer.scheduleAtFixedRate(task, decayPeriodMillis, decayPeriodMillis);
MetricsProxy prox = MetricsProxy.getInstance(ns);
prox.setDelegate(this);
}
示例7: startSubmitting
import java.util.Timer; //導入方法依賴的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!
}
示例8: startSubmitting
import java.util.Timer; //導入方法依賴的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, () -> 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!
}
示例9: checkFill
import java.util.Timer; //導入方法依賴的package包/類
private void checkFill(final String order_id) {
final Timer t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
gdaxApi.getOrder(order_id, new GdaxApi.Listener() {
@Override
public void onSuccess(JsonNode response) {
if (response.get("status").asText().equals("done")) {
t.cancel();
t.purge();
String reason = response.get("done_reason").asText();
if (reason.equals("filled")) {
sendSuccessNotification(response.get("specified_funds").asDouble(), response.get("filled_size").asText());
} else {
sendFailureNotification(reason);
}
}
}
@Override
public void onFailure(String message) {
}
});
}
}, 200, 2000);
}
示例10: startTimer
import java.util.Timer; //導入方法依賴的package包/類
private void startTimer(int emitEveryNumSeconds) {
cancelTimer();
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
liveData.postValue(String.valueOf(random.nextInt(100)));
}
}, 500, emitEveryNumSeconds * 1000);
}
示例11: imprimirTotalSubLoop
import java.util.Timer; //導入方法依賴的package包/類
private void imprimirTotalSubLoop(){
int delay = 0; // delay de 0 seg.
int interval = 10000; // intervalo de 10 seg.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
UsuarioDAO udao = new UsuarioDAO();
int s;
s = udao.getSubm(System.getProperty("login"));
totalSub.setText(String.valueOf(s));
}
}, delay, interval);
}
示例12: schedule
import java.util.Timer; //導入方法依賴的package包/類
private void schedule() {
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (listener != null) {
listener.onTimer();
}
}
}, 0, timerPeriod);
}
示例13: start
import java.util.Timer; //導入方法依賴的package包/類
/**
* Constructs cron jobs and schedules them.
*/
public static void start() {
logger.info("Constructing Cron Service....");
shutdown();
final RuntimeEnv runtimeEnv = Latkes.getRuntimeEnv();
try {
switch (runtimeEnv) {
case LOCAL:
loadCronXML();
for (final Cron cron : CRONS) {
cron.setURL(Latkes.getServer() + Latkes.getContextPath() + cron.getURL());
final Timer timer = new Timer();
TIMERS.add(timer);
timer.scheduleAtFixedRate(cron, Cron.TEN * Cron.THOUSAND, cron.getPeriod());
logger.debug("Scheduled a cron job[url={}]", cron.getURL());
}
logger.debug("[{}] cron jobs totally", CRONS.size());
break;
default:
throw new RuntimeException("Latke runs in the hell.... Please set the enviornment correctly");
}
} catch (final Exception e) {
logger.error("Can not initialize Cron Service!", e);
throw new IllegalStateException(e);
}
logger.info("Constructed Cron Service");
}
示例14: startGCTimer
import java.util.Timer; //導入方法依賴的package包/類
private void startGCTimer() {
gcTimer = new Timer(true);
long timerPeriod = ConstantsAndDefaults.GC_PERIOD_MILLISECONDS;
gcTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
GC.invoke();
}
}, timerPeriod, timerPeriod);
}
示例15: startMonitoring
import java.util.Timer; //導入方法依賴的package包/類
public void startMonitoring() {
int pollingIntervalMin = service.getPrefs().getPreferenceIntegerValue(SipConfigManager.NETWORK_ROUTES_POLLING);
Log.d(THIS_FILE, "Start monitoring of route file ? " + pollingIntervalMin);
if(pollingIntervalMin > 0) {
pollingTimer = new Timer("RouteChangeMonitor", true);
pollingTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
String currentRoutes = dumpRoutes();
String oldRoutes;
synchronized (mRoutes) {
oldRoutes = mRoutes;
}
if(!currentRoutes.equalsIgnoreCase(oldRoutes)) {
Log.d(THIS_FILE, "Route changed");
// Run the handler in SipServiceExecutor to be protected by wake lock
service.getExecutor().execute(new SipRunnable() {
public void doRun() throws SameThreadException {
onConnectivityChanged(null, false);
}
});
}
}
}, new Date(), pollingIntervalMin * 60 * 1000);
}
}