List of usage examples for java.util Timer Timer
public Timer()
From source file:org.powertac.server.SimulationClockControl.java
private SimulationClockControl(CompetitionControlService competitionControl, TimeService timeService) { super();/*w w w .j a v a 2 s . co m*/ this.competitionControl = competitionControl; this.timeService = timeService; this.base = timeService.getBase(); this.rate = timeService.getRate(); this.modulo = timeService.getModulo(); theTimer = new Timer(); }
From source file:gsn.vsensor.AbstractScheduledVirtualSensor.java
/** * Called once while initializing an instance of the virtual sensor * Gets schedule parameters from VSD, calculates timer parameters and instantiates timer instance. * /*from w ww.jav a2 s . c o m*/ * @return True if the initialization is done successfully. */ public boolean initialize() { TreeMap<String, String> params = getVirtualSensorConfiguration().getMainClassInitialParams(); String rate_value = params.get(RATE_PARAM); if (rate_value == null) { logger.warn("Parameter \"" + RATE_PARAM + "\" not provider in Virtual Sensor file"); return false; } clock_rate = Integer.parseInt(rate_value); String start_value = params.get(START_PARAM); if (start_value != null) { //start value set in VSD try { startTime = Helpers.convertTimeFromIsoToLong(start_value); } catch (Exception e) { logger.error( "Failed to parse the start-time parameter of the remote wrapper, a sample time could be:" + (CURRENT_TIME)); throw new RuntimeException(e); } } // If the scheduled start is not in the future // then start at the next whole time interval if (System.currentTimeMillis() >= startTime) { startTime = System.currentTimeMillis(); // current time // Calculate from midnight long midnight = DateUtils.truncate(new Date(), Calendar.DATE).getTime(); long current_time = System.currentTimeMillis(); // Start startTime = midnight + (((current_time - midnight) / clock_rate) + 1) * clock_rate; } //otherwise use the time retrieved from the VSD logger.warn(getVirtualSensorConfiguration().getName() + " scheduled to start at " + new Date(startTime).toString()); // startTime is used in the virtual sensor class to start a timer timer0 = new Timer(); // timer task is started in the sub class return true; }
From source file:com.firma.dev.letschat.MyFavoriteFragment.java
private void forceUpdate() { getUserContactsTask.cancel();/*w ww . ja va2 s . c o m*/ userContactsTimer.cancel(); userContactsTimer.purge(); userContactsTimer = new Timer(); getUserContactsTask = new GetUserContactsTask(); userContactsTimer.schedule(getUserContactsTask, 0, 60000); }
From source file:com.example.hasan.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The ArrayAdapter will take data from a source and // use it to populate the ListView it's attached to. mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity) R.layout.list_item_forecast, // The name of the layout ID. R.id.list_item_forecast_textview, // The ID of the textview to populate. new ArrayList<String>()); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); /*listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { //from w w w.java 2s.c o m @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Intent intent = new Intent(getActivity(), DetailActivity.class) .putExtra(Intent.EXTRA_TEXT, forecast); startActivity(intent); } });*/ WeatherTimerTask myTask = new WeatherTimerTask(); Timer myTimer = new Timer(); myTimer.schedule(myTask, 10000, 300000); return rootView; }
From source file:ExampleMIDlet.java
private void startTimer() { // Create a task to be run task = new TimerTask() { private boolean isPaused; private int count; public void run() { // Pause or resume the MIDlet. System.out.println("Timer scheduled"); if (count++ == 4) { // Terminate the MIDlet try { ExampleMIDlet.this.destroyApp(true); } catch (MIDletStateChangeException ex) { // Ignore pleas for mercy! }/*from w ww . j a v a 2 s . co m*/ ExampleMIDlet.this.notifyDestroyed(); return; } if (isPaused) { System.out.println(">> Resuming MIDlet"); ExampleMIDlet.this.resumeRequest(); isPaused = false; } else { System.out.println(">> Pausing MIDlet"); isPaused = true; ExampleMIDlet.this.pauseApp(); ExampleMIDlet.this.notifyPaused(); } } }; // Create a timer and schedule it to run timer = new Timer(); timer.schedule(task, timerInterval, timerInterval); System.out.println("Timer started."); }
From source file:com.purplefrog.glitchclocka.LearningReadout.java
public synchronized void ensureTimerRunning() { if (timer != null) return;// www . j a va2 s . c o m TimerTask timerTask = new TimerTask() { @Override public void run() { updateProgressTimeBar(); } }; timer = new Timer(); timer.scheduleAtFixedRate(timerTask, 0, 10000); }
From source file:morphy.user.SocketChannelUserSession.java
public void scheduleIdleTimeout() { if (idleLogoutTimer != null) idleLogoutTimer.cancel();//from www . ja v a 2s . c om // admins don't idle out if (UserService.getInstance().isAdmin(getUser().getUserName())) { return; } /*LOG.info("scheduling " + getUser().getUserName() + " for idle logout (60 minutes)");*/ final int millis = 60 * 60 * 1000; if (idleLogoutTimer != null) idleLogoutTimer.cancel(); final UserSession sess = this; idleLogoutTimer = new Timer(); idleLogoutTimer.schedule(new java.util.TimerTask() { public void run() { if (getIdleTimeMillis() >= millis - 1) { send("\n\n**** Auto-logout because you were idle for 60 minutes ****\n"); if (isExamining()) { GameService gs = GameService.getInstance(); GameInterface gi = gs.map.get(sess); if (gi != null) { gs.unexamineGame(sess); } } disconnect(); } else { idleLogoutTimer.purge(); scheduleIdleTimeout(); // recursion } } }, 60 * 60 * 1000); }
From source file:org.spee.sbweb.controller.SBWebController.java
@Override public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; System.out.println(/*from ww w . ja v a2 s . c o m*/ "SBWebControler.java - ServletContext: images - " + this.servletContext.getRealPath("/images")); System.out.println("SBWebControler.java - ServletContext: root - " + this.servletContext.getRealPath("/")); Timer t = new Timer(); CronJobs mTask = new CronJobs(); t.scheduleAtFixedRate(mTask, 0, TIME_TO_CHECK_IMAGE_FOLDER); }
From source file:com.cyberlogix.mist6020biometrics.RosterController.java
public void printsListener() { long delay = 5 * 1000; final long period = 5 * 1000; Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override//from ww w . ja va 2 s. co m public void run() { Platform.runLater(new Runnable() { @Override public void run() { String b64Print = bio.getImage(rosterImage, rosterPbar, rosterPin, new Stage(), period); System.out.println("Print: " + b64Print); try { if (!b64Print.equalsIgnoreCase("error")) { String url = ServerConnect.STUDENTS_URL + "/verify"; ServerConnect sc = new ServerConnect(); JSONObject req = new JSONObject(); req.put("print", b64Print); ServerResponse msg = sc.processRequest(req.toString(), url, ServerConnect.METHOD_POST); if (msg.getStatusCode() == 200 || msg.getStatusCode() == 201) { ObjectMapper jackson = new ObjectMapper(); Student student = jackson.readValue( msg.getResponse().getJSONObject("payload").toString(), Student.class); //update table int pos = -1; ObservableList<Student> students = tblRoster.getItems(); for (int i = 0; i < students.size(); i++) { if (students.get(i).getId() == student.getId()) { System.out.println("Student Matched..."); student.setSignedIn("Present"); students.remove(students.get(i)); pos = i; } } if (pos >= 0) { students.add(pos, student); } System.out.println("Students Size: " + students.size()); tblRoster.setItems(students); // Dialogs.showConfirmDialog(new Stage(), msg.getResponse().getString("message") + " " + student.getName()); alertBox.setText( msg.getResponse().getString("message") + " " + student.getName()); alertBox.setStyle("-fx-text-fill: green; -fx-font-weight: bold;"); } else { // Dialogs.showErrorDialog(new Stage(), msg.getResponse().getString("message"), "Error " + msg.getStatusCode(), "Error"); alertBox.setText(msg.getResponse().getString("message")); alertBox.setStyle("-fx-text-fill: red; -fx-font-weight: bold;"); } } } catch (JSONException | IOException e) { UtilHelper.debugTrace(e); } } }); } }, delay, period); }
From source file:idgs.client.TcpClientPool.java
private void loadClientConfig() { log.debug(cfg.toString());/*from www . j ava 2s . c o m*/ init(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { int poolSize = -1; if (running.get() && (poolSize = size()) <= 0) { log.warn( "no available client to use, will auto create 2 multiples clients of config pool size"); newConnection(cfg.getPoolSize() * loadFactor); poolSize = size(); log.info("new pool size: " + poolSize); } } }, 5000, 3000); }