List of usage examples for java.util Timer schedule
public void schedule(TimerTask task, Date firstTime, long period)
From source file:com.spend.spendService.DomainLearning.java
private void GetNewQuery() { try {//from w ww .ja v a 2s . c om TimerTask timertask = new TimerTask() { public void run() { try { domainList = new ArrayList<String>(); String[] seList = getSearchEngineNamesArray(); /* get urls from seedurlraw table */ PreparedStatement psmt = con.prepareStatement("SELECT url FROM seedurlraw"); ResultSet rs = psmt.executeQuery(); String regex = "[/]"; String regex2 = "[.]"; String PLDomain; while (rs.next()) { PLDomain = rs.getString("url"); PLDomain = PLDomain.replaceAll("http://|https://", ""); Pattern p = Pattern.compile(regex); Matcher m = p.matcher(PLDomain); if (m.find()) { PLDomain = PLDomain.substring(0, m.start()); } Pattern p2 = Pattern.compile(regex2); Matcher m2 = p2.matcher(PLDomain); int count = 0; while (m2.find()) { count++; } m2 = p2.matcher(PLDomain); if (count > 1 && m2.find()) { PLDomain = PLDomain.substring(m2.end()); } //System.out.println(PLDomain); if (!domainList.contains(PLDomain)) { domainList.add(PLDomain); newQuery = "sparql endpoint site:" + PLDomain; for (Object se : seList) { PreparedStatement psmt1 = con.prepareStatement( "INSERT INTO searchqueue(searchText,disabled,searchEngineName) VALUES(?,0,?);"); psmt1.setString(1, newQuery); psmt1.setString(2, se.toString()); psmt1.executeUpdate(); psmt1.close(); } } } } catch (Exception ex) { System.out .println("DomainLearning.java timertask run function SQL ERROR " + ex.getMessage()); } } }; Timer timer = new Timer(); DateFormat dateformat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); Date date = dateformat.parse("20-07-2017 00:00:00"); // set date and time timer.schedule(timertask, date, 1000 * 60 * 60 * 24 * 7); // for a week 1000*60*60*24*7 } catch (Exception ex) { System.out.println("DomainLearning.java GetNewQuery function ERROR " + ex.getMessage()); } }
From source file:com.app.imagecreator.activities.HomeActivity.java
private void refreshImage(int pos) { position = pos + 1;/* w w w. j a va2 s.c om*/ Timer mTimerPromotions = new Timer(); mTimerPromotions.schedule(new RefreshPromotionsTask(), 5000, 3000); }
From source file:org.sipfoundry.sipxconfig.admin.DailyBackupSchedule.java
public void schedule(Timer timer, TimerTask task) { if (!isEnabled()) { return;/*from w ww .jav a 2s. c om*/ } Date date = getTimerDate(); long period = getTimerPeriod(); LOG.info("Setting timer for " + LOCAL_TIME_OF_DAY_FORMAT.format(date)); timer.schedule(task, date, period); }
From source file:pt.lsts.neptus.plugins.controllers.ControllerManager.java
/** * Create a control loop// ww w. ja v a 2s. c o m * @param controller The controller in charge * @param vehicle The vehicle being controlled * @param controlLatencySeconds * @throws Exception */ public void associateControl(final IController controller, final VehicleType vehicle, int controlLatencySeconds, int timeoutSeconds) throws Exception { EstimatedState lastState = ImcMsgManager.getManager().getState(vehicle).last(EstimatedState.class); if (!controller.supportsVehicle(vehicle, lastState)) { throw new Exception("The vehicle " + vehicle.getName() + " is not supported by " + controller.getControllerName() + " controller"); } PlanControl startPlan = new PlanControl(); startPlan.setType(TYPE.REQUEST); startPlan.setOp(OP.START); startPlan.setPlanId(controller.getControllerName()); FollowReference man = new FollowReference(); man.setControlEnt((short) 255); man.setControlSrc(65535); man.setAltitudeInterval(1); man.setTimeout(timeoutSeconds); man.setLoiterRadius(7.5); PlanSpecification spec = new PlanSpecification(); spec.setPlanId(controller.getControllerName()); spec.setStartManId("external_control"); PlanManeuver pm = new PlanManeuver(); pm.setData(man); pm.setManeuverId("external_control"); spec.setManeuvers(Arrays.asList(pm)); startPlan.setArg(spec); int reqId = 0; startPlan.setRequestId(reqId); startPlan.setFlags(0); ImcMsgManager.getManager().sendMessageToSystem(startPlan, vehicle.getId()); /* if (useAcousticComms) { AcousticOperation op = new AcousticOperation(); op.setOp(AcousticOperation.OP.MSG); op.setSystem(vehicle.getId()); op.setMsg(startPlan); }*/ if (debug) System.out.println(controller.getControllerName() + " is now controlling " + vehicle.getId()); controller.startControlling(vehicle, lastState); activeControllers.put(vehicle.getName(), controller); TimerTask task = new TimerTask() { @Override public void run() { EstimatedState state = ImcMsgManager.getManager().getState(vehicle.getId()) .last(EstimatedState.class); FollowRefState frefState = ImcMsgManager.getManager().getState(vehicle.getId()) .last(FollowRefState.class); Reference ref = controller.guide(vehicle, state, frefState); try { System.out.println("size in bytes of the reference message: " + ref.serialize(new IMCOutputStream(new ByteArrayOutputStream(256)))); } catch (Exception e) { e.printStackTrace(); } if (useAcousticComms) { // alwas try to send using wifi ImcMsgManager.getManager().sendMessageToSystem(ref, vehicle.getId()); AcousticOperation op = new AcousticOperation(); op.setOp(AcousticOperation.OP.MSG); op.setSystem(vehicle.getId()); op.setMsg(ref); ImcSystem[] sysLst = ImcSystemsHolder.lookupSystemByService("acoustic/operation", SystemTypeEnum.ALL, true); if (sysLst.length == 0) { NeptusLog.pub() .error("Cannot send reference acoustically because no system is capable of it"); return; } int successCount = 0; for (ImcSystem sys : sysLst) { if (ImcMsgManager.getManager().sendMessage(op, sys.getId(), null)) { successCount++; NeptusLog.pub().warn( "Sent reference to " + vehicle.getId() + " acoustically via " + sys.getName()); } } if (successCount == 0) { NeptusLog.pub() .error("Cannot send reference acoustically because no system is capable of it"); } } else { ImcMsgManager.getManager().sendMessageToSystem(ref, vehicle.getId()); } } }; Timer t = new Timer(controller.getControllerName() + " control timer", true); t.schedule(task, 0, controlLatencySeconds * 1000); timers.put(vehicle.getId(), t); }
From source file:com.jigarmjoshi.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (SimpleDatabaseUtil.isFirstApplicationStart(this)) { Log.i(MainActivity.class.getSimpleName(), "creating database for the first time"); SQLiteSimple databaseSimple = new SQLiteSimple(this, DATABASE_VERSION); databaseSimple.create(Report.class, LastLocation.class); } else if (SimpleDatabaseUtil.isFirstStartOnAppVersion(this, DATABASE_VERSION)) { Log.i(MainActivity.class.getSimpleName(), "creating database for the first time for this version " + DATABASE_VERSION); SQLiteSimple databaseSimple = new SQLiteSimple(this, DATABASE_VERSION); databaseSimple.create(Report.class, LastLocation.class); }//from w w w . j a v a 2s . c o m // initialize services EntryDao.getInstance(this); LastLocationDao.getInstance(this); // scheduler mgr = (AlarmManager) getSystemService(ALARM_SERVICE); Intent i = new Intent(this, LocationPoller.class); com.jigarmjoshi.service.LocationManager locationManager = com.jigarmjoshi.service.LocationManager .getInstance(getApplicationContext()); List<String> providers = locationManager.getAllProviders(); boolean fusedSupported = false; for (String provider : providers) { if (com.jigarmjoshi.service.LocationManager.FUSED_PROVIDER.equals(provider)) { fusedSupported = true; break; } } i.putExtra(LocationPoller.EXTRA_INTENT, new Intent(this, com.jigarmjoshi.reciever.LocationReceiver.class)); i.putExtra(LocationPoller.EXTRA_PROVIDER, (fusedSupported ? LocationManager.FUSED_PROVIDER : LocationManager.GPS_PROVIDER)); pi = PendingIntent.getBroadcast(this, 0, i, 0); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0, Long.parseLong(ConfigService.get(ConfigService.GPS_TASK_INTERVAL, "40000")), pi); // upload task Timer timer = new Timer(); TimerTask timerTask = new UploaderTask(this); timer.schedule(timerTask, 0, Long.parseLong(ConfigService.get(ConfigService.UPLOAD_TASK_INTERVAL, "40000"))); selectedTextView = new TextView(this); selectedTextView.setTextColor(Color.BLACK); selectedTextView.setGravity(Gravity.CENTER); selectedTextView.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG); unSelectedTextView = new TextView(this); unSelectedTextView.setTextColor(Color.GRAY); unSelectedTextView.setGravity(Gravity.CENTER); unSelectedTextView.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG); // create if first time getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); actionBar = getActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#40808080"))); actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#40808080"))); setContentView(R.layout.activity_main); // Initilization viewPager = (ViewPager) findViewById(R.id.pager); mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Adding Tabs boolean first = false; for (String tab_name : tabs) { Tab tab = actionBar.newTab().setText(tab_name).setTabListener(this); if (first) { first = false; selectedTextView.setText(tab.getText().toString().toUpperCase(Locale.getDefault())); tab.setCustomView(selectedTextView); } else { unSelectedTextView.setText(tab.getText().toString().toUpperCase(Locale.getDefault())); tab.setCustomView(unSelectedTextView); } actionBar.addTab(tab); } /** * on swiping the viewpager make respective tab selected * */ viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page // make respected tab selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); Toast.makeText(this, getString(R.string.wait_gps), Toast.LENGTH_LONG).show(); }
From source file:fr.calamus.common.db.core.DbCentralFactory.java
protected static void launchInstancesObserver() { if (!instancesObserverIsLaunched) { Timer timer = new Timer("DbFactory-instancesRemover", true); TimerTask task = new TimerTask() { @Override/*from ww w . j a va 2 s .c o m*/ public void run() { synchronized (instances) { long now = System.currentTimeMillis(); List<String> toRemove = new ArrayList<>(); for (String id : instances.keySet()) { DbCentralFactory db = instances.get(id); if (id != null && (db == null || now > db.lastUsedTime() + db.cnxTimeOut())) { toRemove.add(id); } } for (String id : toRemove) { DbCentralFactory db = instances.get(id); if (db != null) { db.close(); } instances.remove(id); } if (toRemove.size() > 0) { log.debug("removed " + toRemove.size() + " instance(s); remaining " + instances.size()); } } } }; timer.schedule(task, 30000, 10000); instancesObserverIsLaunched = true; } }
From source file:org.n52.io.PreRenderingTask.java
public void startTask() { if (taskToRun != null) { this.enabled = true; Timer timer = new Timer("Prerender charts timer task"); timer.schedule(taskToRun, 10000, getPeriodInMilliseconds()); }/*from w w w .j a va2 s. c o m*/ }
From source file:org.alfresco.bm.test.TestRunServicesCache.java
@Override public void start() throws Exception { Timer timer = new Timer("TestServicesCache", true); timer.schedule(contextCleanerTask, 0L, CONTEXT_ACCESS_TIMEOUT); }
From source file:orca.shirako.container.ActorLiveness.java
public ActorLiveness(String input_act_guid, String input_registryUrl) { act_guid = input_act_guid;/* ww w . j a v a 2 s. co m*/ registryUrl = input_registryUrl; Timer timer = null; synchronized (timers) { if (noStart) return; timer = new Timer("ActorLiveness: " + act_guid, true); timers.add(timer); } timer.schedule(new TalkToRegistry2(), 60 * 1000, 60 * 1000); }
From source file:orca.shirako.container.ActorLiveness.java
public ActorLiveness(String input_act_guid, String input_registryUrl, String input_registryMethod) { act_guid = input_act_guid;//from www.j a v a 2 s .c o m registryUrl = input_registryUrl; registryMethod = input_registryMethod; Timer timer = null; synchronized (timers) { if (noStart) return; timer = new Timer("ActorLiveness: " + act_guid, true); timers.add(timer); } timer.schedule(new TalkToRegistry(), 60 * 1000, 60 * 1000); }