當前位置: 首頁>>代碼示例>>Java>>正文


Java Timer類代碼示例

本文整理匯總了Java中java.util.Timer的典型用法代碼示例。如果您正苦於以下問題:Java Timer類的具體用法?Java Timer怎麽用?Java Timer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Timer類屬於java.util包,在下文中一共展示了Timer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: selfDestruct

import java.util.Timer; //導入依賴的package包/類
public static void selfDestruct(Message message, long delay) {
    if (message == null) return;

    new Timer().schedule(new TimerTask() {
        @Override
        public void run() {
            message.delete().complete();
        }
    }, delay);
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:11,代碼來源:MessageUtil.java

示例2: 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!
}
 
開發者ID:Slaymd,項目名稱:CaulCrafting,代碼行數:27,代碼來源:Metrics.java

示例3: updateTime

import java.util.Timer; //導入依賴的package包/類
private void updateTime() {
    Timer commandExecutionTimer = new Timer();
    commandExecutionTimer.schedule(new TimerTask() {

        @Override
        public void run() {

                    doSetTrackInfo();
                    if (updateTime) {
                        updateTime();
                    }
                }


    }, 1000L);

}
 
開發者ID:theopenbit,項目名稱:yaacc-code,代碼行數:18,代碼來源:AvTransportMediaRendererPlaying.java

示例4: onCreate

import java.util.Timer; //導入依賴的package包/類
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Timer timer = new Timer();
        TimerTask updateTask = new TimerTask() {
            @Override
            public void run() {
                executeUpdate();
            }
        };

        TimerTask scrollTask = new TimerTask() {
            @Override
            public void run() {
                scrollTab();
            }
        };

        timer.schedule(updateTask, 1, 240000);
//        timer.schedule(scrollTask, 10000, 10000);
    }
 
開發者ID:bitcoinbull,項目名稱:biniu-index,代碼行數:23,代碼來源:MainActivity.java

示例5: 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!
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:23,代碼來源:Metrics.java

示例6: stop

import java.util.Timer; //導入依賴的package包/類
@Override
public void stop() {
    // 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
    // in order 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(ImageViewerBroadcastReceiver.ACTION_STOP);
            context.sendBroadcast(intent);

        }
    }, getExecutionTime());

}
 
開發者ID:theopenbit,項目名稱:yaacc-code,代碼行數:21,代碼來源:LocalImagePlayer.java

示例7: main

import java.util.Timer; //導入依賴的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

示例8: run

import java.util.Timer; //導入依賴的package包/類
/**遊戲運行的方法*/
public void run() {
	//鍵盤監聽
	keyListener();
	//生成下一個落下的方格
	createAction();
	//方格進入遊戲區
	enterAction();
		Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			public void run() {
					//方格下落及合並
					addAction();
			}
		}, 100, 20);
}
 
開發者ID:brandonbai,項目名稱:game2048_tetris,代碼行數:17,代碼來源:DropPanel.java

示例9: 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!
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:23,代碼來源:BMetrics.java

示例10: ConnectionManager

import java.util.Timer; //導入依賴的package包/類
ConnectionManager() {
  this.idleScanTimer = new Timer(
      "IPC Server idle connection scanner for port " + getPort(), true);
  this.idleScanThreshold = conf.getInt(
      CommonConfigurationKeysPublic.IPC_CLIENT_IDLETHRESHOLD_KEY,
      CommonConfigurationKeysPublic.IPC_CLIENT_IDLETHRESHOLD_DEFAULT);
  this.idleScanInterval = conf.getInt(
      CommonConfigurationKeys.IPC_CLIENT_CONNECTION_IDLESCANINTERVAL_KEY,
      CommonConfigurationKeys.IPC_CLIENT_CONNECTION_IDLESCANINTERVAL_DEFAULT);
  this.maxIdleTime = 2 * conf.getInt(
      CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY,
      CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_DEFAULT);
  this.maxIdleToClose = conf.getInt(
      CommonConfigurationKeysPublic.IPC_CLIENT_KILL_MAX_KEY,
      CommonConfigurationKeysPublic.IPC_CLIENT_KILL_MAX_DEFAULT);
  this.maxConnections = conf.getInt(
      CommonConfigurationKeysPublic.IPC_SERVER_MAX_CONNECTIONS_KEY,
      CommonConfigurationKeysPublic.IPC_SERVER_MAX_CONNECTIONS_DEFAULT);
  // create a set with concurrency -and- a thread-safe iterator, add 2
  // for listener and idle closer threads
  this.connections = Collections.newSetFromMap(
      new ConcurrentHashMap<Connection,Boolean>(
          maxQueueSize, 0.75f, readThreads+2));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:Server.java

示例11: isStartTimer

import java.util.Timer; //導入依賴的package包/類
public void isStartTimer() {
	secondleft = 60;
	timer = new Timer();
	timer.schedule(new TimerTask() {
		@Override
		public void run() {
			secondleft--;
			int progress = (int) ((60 - secondleft) * (100 / 60.0));
			if(progress<=100){
				timerText = getResources().getString(R.string.finding_smart_tv,progress)+ "%)";
				mHandler.sendEmptyMessage(HandlerKey.TIMER_TEXT.ordinal());
			}
			
		}
	}, 1000, 1000);
}
 
開發者ID:yaokantv,項目名稱:YKCenterDemo-Android,代碼行數:17,代碼來源:YKWifiConfigActivity.java

示例12: await

import java.util.Timer; //導入依賴的package包/類
public void await() {
    if(0 == delay) {
        log.info("No pause between retry");
        return;
    }
    final Timer wakeup = new Timer();
    final CyclicBarrier wait = new CyclicBarrier(2);
    // Schedule for immediate execution with an interval of 1s
    wakeup.scheduleAtFixedRate(new PauserTimerTask(wait), 0, 1000);
    try {
        // Wait for notify from wakeup timer
        wait.await();
    }
    catch(InterruptedException | BrokenBarrierException e) {
        log.error(e.getMessage(), e);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:18,代碼來源:BackgroundActionPauser.java

示例13: scheduleWork

import java.util.Timer; //導入依賴的package包/類
@Override
public boolean scheduleWork(String workName, AbstractTimerWork r, Date firstDate, long period) {

    if (checkNull(workName, r, firstDate, period)) {
        return false;
    }

    Timer t = new Timer(workName, r.isDaemon());
    r.setTimer(t);
    r.setPeriod(period);
    TimerTask tt = createTimerTask(workName, r);

    try {
        t.scheduleAtFixedRate(tt, firstDate, period);
        return true;
    }
    catch (Exception e) {
        log.err(this, "Timer Worker[" + r.getName() + "] starts FAIL.", e);
    }

    return false;
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:23,代碼來源:SystemTimerWorkMgr.java

示例14: defineBroadcastReceiverFor

import java.util.Timer; //導入依賴的package包/類
private BroadcastReceiver defineBroadcastReceiverFor(final FlowableEmitter<SensorRecord> subscriber){
    return new BroadcastReceiver() {
        Timer timer = new Timer();
        long prevCallTime = new Date().getTime();

        @Override
        public void onReceive(Context context, Intent intent) {
            long actualTime = new Date().getTime();
            long delay = calculateDiffDelay(prevCallTime, actualTime);
            prevCallTime = actualTime;

            subscriber.onNext(new WifiMeasurementsRecord(wifiManager.getScanResults()));

            if (delay > 0)
                timer.schedule(createScanTask(), delay);
            else
                createScanTask().run();
        }
    };
}
 
開發者ID:ubikgs,項目名稱:AndroidSensors,代碼行數:21,代碼來源:WifiMeasurementsGatherer.java

示例15: countTime

import java.util.Timer; //導入依賴的package包/類
/**
 * 倒計時
 */
private void countTime() {
    mTimer = new Timer();
    mTask = new TimerTask() {

        @Override
        public void run() {
            mSeconds = mSeconds - 1;
            Message msg = Message.obtain();
            msg.what = 1;
            msg.obj = mSeconds;
            mTimeHandler.sendMessage(msg);
        }
    };
    mTimer.schedule(mTask, 0, 1000);
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:19,代碼來源:GameActivity.java


注:本文中的java.util.Timer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。