List of usage examples for java.util Timer Timer
public Timer(String name)
From source file:com.perfect.autosdk.core.JsonProxy.java
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String addr = service.serverUrl + AddressUtil.getJsonAddr(interfaces) + '/' + method.getName(); JsonConnection conn = new GZIPJsonConnection(addr); conn.setConnectTimeout(service.connectTimeoutMills); conn.setReadTimeout(service.readTimeoutMills); JsonEnvelop request = makeRequest(args[0]); conn.sendRequest(request);//w ww . j a v a 2 s. c o m JsonEnvelop<ResHeader, ?> response = conn.readResponse(ResHeader.class, method.getReturnType()); ResHeader resHeader = response.getHeader(); if (!resHeader.getFailures().isEmpty()) { if (log.isErrorEnabled()) { log.error("Call Error: Head info = " + resHeader + "\n" + "account info = " + service.getUsername() + "\n" + "request info = " + addr + "\n" + "request param = " + args[0]); } if (resHeader.getFailures().get(0).getCode() == 8904) { Timer timer = new Timer("waitLock"); final CountDownLatch latch = new CountDownLatch(1); timer.schedule(new TimerTask() { @Override public void run() { System.out.println("waiting...."); latch.countDown(); } }, 15000); latch.await(); } } ResHeaderUtil.resHeader.set(response.getHeader()); BaiduApiQuota.setQuota(service.username, response.getHeader().getQuota()); return response.getBody(); }
From source file:edu.cens.loci.sensors.AccelerometerHandler.java
public void start() { if (mIsOn)// ww w . ja v a2 s .c om return; mCpuLock = cpu().newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AccelerometerHandler.CpuLock"); mCpuLock.setReferenceCounted(false); mIsOn = true; if (mDuration > 0) { //mCpuLock.acquire(); mOnTimer = new Timer("sensorTurnOnTimer"); mOffTimer = new Timer("sensorTurnOffTimer"); mOnTimer.scheduleAtFixedRate(new TimerTask() { public void run() { mSensorService = (SensorManager) mCxt.getSystemService(Context.SENSOR_SERVICE); synchronized (this) { MyLog.i(LociConfig.D.ACC, TAG, "[ACC] ON "); mCpuLock.acquire(); mSensorOn = true; mSensorService.registerListener(sInstance, mSensorService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), mRate); } } }, 0, mPeriod); mOffTimer.scheduleAtFixedRate(new TimerTask() { public void run() { synchronized (this) { MyLog.i(LociConfig.D.ACC, TAG, "[ACC] OFF "); mSensorOn = false; if (mCpuLock.isHeld()) mCpuLock.release(); mSensorService.unregisterListener(sInstance, mSensorService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); } // time to turn off sensor -- somehow send data //mXArr.reset(); //mYArr.reset(); //mZArr.reset(); long time = Calendar.getInstance().getTime().getTime(); float magVar = getMagnitudeVariance(); //LociMobileManagerService.getInstance().eventAccelerometerResult(Calendar.getInstance().getTime().getTime(), magVar); mListener.onAccelerometerChanged(time, magVar); //if (LociMobileManagerService.getInstance().isMDOn()) // LociMobileManagerService.getInstance().getSystemDb().updatePowerRow(SystemLogDbAdapter.SENSOR_ACC, System.currentTimeMillis()); } }, mDuration, mPeriod); } else { mCpuLock.acquire(); mSensorService = (SensorManager) mCxt.getSystemService(Context.SENSOR_SERVICE); mSensorService.registerListener(this, mSensorService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), mRate); mReportTimer = new Timer("SensorReportTimer"); mReportTimer.scheduleAtFixedRate(new TimerTask() { public void run() { // send data long time = Calendar.getInstance().getTime().getTime(); float magVar = getMagnitudeVariance(); mListener.onAccelerometerChanged(time, magVar); //LociMobileManagerService.getInstance().eventAccelerometerResult(Calendar.getInstance().getTime().getTime(), magVar); //if (LociMobileManagerService.getInstance().isMDOn()) // LociMobileManagerService.getInstance().getSystemDb().updatePowerRow(SystemLogDbAdapter.SENSOR_ACC, System.currentTimeMillis()); } }, 0, mDuration); } //LociMobileManagerService.getInstance().getSystemDb().addPowerRow(SystemLogDbAdapter.SENSOR_ACC, System.currentTimeMillis()); startChkTimer(); }
From source file:com.dc.tes.License.java
private static void HeadBeat() { new Timer(true).schedule(new TimerTask() { @Override// www . ja va 2 s . co m public void run() { Message request = new Message(MessageType.LICENSE); request.put(MessageItem.LICENSE.SIGN, 1); request.put(MessageItem.LICENSE.PORT, CORE_PORT); request.put(MessageItem.LICENSE.SYSNAME, Sys_Name); System.out.println("" + request); String license = LicenseServerConnect(request); if (license.length() > 0) { log.error("lisence?,"); System.exit(-1); } } }, 500, 60 * 1000); }
From source file:me.Aron.Heinecke.fbot.fbot.java
/**** * registers the timed task to download both pdfs *//* w w w . ja v a2 s .co m*/ private static void registerThreads() { maintimer = new Timer(true); filetask = new TimerTask() { public void run() { hash1 = Task(0, hash1); hash2 = Task(1, hash2); } }; maintimer.schedule(filetask, 0, 1000 * interval);// 1000*sec }
From source file:cc.arduino.packages.discoverers.NetworkDiscovery.java
@Override public void start() throws IOException { this.networkCheckerTimer = new Timer(NetworkChecker.class.getName()); new NetworkChecker(this, NetworkTopologyDiscovery.Factory.getInstance()).start(networkCheckerTimer); this.boardReachabilityFilterTimer = new Timer(BoardReachabilityFilter.class.getName()); new BoardReachabilityFilter(this).start(boardReachabilityFilterTimer); }
From source file:fr.seeks.SuggestionProvider.java
public void perhapsSetCursorOfQuery(Uri uri, String query, MatrixCursor matrix) { if (query == "") return;/*from ww w . j a v a2s. co m*/ if (mTimer != null) { mTimer.cancel(); } mTimer = new Timer(true); mTimer.schedule(new SuggestionTimerTask(uri, query, matrix), 500); }
From source file:mondrian.util.UtilCompatibleJdk14.java
public Timer newTimer(String name, boolean isDaemon) { return new Timer(isDaemon); }
From source file:org.geppetto.samplesimulation.SimulationServlet.java
private void startClientUpdateTimer() { _simTimer = new Timer( SimulationServlet.class.getSimpleName() + " - Timer - " + new java.util.Date().getTime()); _simTimer.scheduleAtFixedRate(new TimerTask() { @Override//from ww w .ja va 2s. com public void run() { try { update(); } catch (RuntimeException e) { // log.error("Caught to prevent timer from shutting down", e); } } }, UPDATE_CYCLE, UPDATE_CYCLE); }
From source file:org.camunda.bpm.extension.elasticsearch.cockpit.demodata.DemoDataGenerator.java
protected void scheduleInstanceStart() { new Timer(true).schedule(new TimerTask() { public void run() { // start some process instances int rand = new Random().nextInt(maxInstances); for (int i = 0; i < rand; i++) { processEngine.getRuntimeService().startProcessInstanceByKey("generatedFormsQuickstart"); }/*from w ww . j av a 2 s . c o m*/ // complete some process instances rand = new Random().nextInt(maxInstances); List<Task> tasks = processEngine.getTaskService().createTaskQuery().listPage(0, rand); for (Task task : tasks) { processEngine.getTaskService().complete(task.getId()); } // reschedule scheduleInstanceStart(); } }, 1000); }
From source file:com.inbravo.scribe.rest.service.crm.cache.CRMSessionCache.java
public final void initialize() { if (cacheManager != null) { cacheManager.cancel();/*from w w w. ja v a2 s .c o m*/ } cacheManager = new Timer(true); cacheManager.schedule(new TimerTask() { public void run() { long now = System.currentTimeMillis(); try { MapIterator itr = cacheMap.mapIterator(); while (itr.hasNext()) { Object key = itr.next(); final CachedObject cobj = (CachedObject) itr.getValue(); if (cobj == null || cobj.hasExpired(now)) { if (logger.isDebugEnabled()) { logger.debug("----Inside CRMSessionCache: removing " + key + ": Idle time= " + (now - cobj.timeAccessedLast) + "; Stale time= " + (now - cobj.timeCached) + "; Object count in cache= " + cacheMap.size()); } itr.remove(); Thread.yield(); } } } catch (ConcurrentModificationException cme) { /* * This is just a timer cleaning up. It will catch up on cleaning next time it runs. */ if (logger.isDebugEnabled()) { logger.debug("----Inside CRMSessionCache:Ignorable ConcurrentModificationException"); } } } }, 0, tiv); }