List of usage examples for java.util Timer scheduleAtFixedRate
public void scheduleAtFixedRate(TimerTask task, Date firstTime, long period)
From source file:xbird.server.services.PerfmonService.java
public void start() throws ServiceException { if (perfmonIntervalnMills == -1 || !LOG.isInfoEnabled()) { return;/*from ww w.ja v a2s .co m*/ } PerfmonTask task = new PerfmonTask(); Timer timer = new Timer(SRV_NAME, true); timer.scheduleAtFixedRate(task, 1000, perfmonIntervalnMills); this._timer = timer; this._status = Status.started; }
From source file:net.pms.util.TempFileMgr.java
public void schedule() { TimerTask task = new TimerTask() { @Override//w w w .j a va 2s . co m public void run() { scan(); } }; Timer t = new Timer(); t.scheduleAtFixedRate(task, 0, INTERVAL); }
From source file:com.necla.simba.server.gateway.Main.java
public void serve() { try {//from w w w.j a v a 2 s.c o m stats = new StatsCollector(); stats.start("gateway.out"); boolean frontendCompression = Boolean .parseBoolean(properties.getProperty("frontend.compression", "true")); FrontendFrameEncoder.DOCOMPRESS = frontendCompression; String nodes = properties.getProperty("simbastores"); List<String> nodeArr = Arrays.asList(nodes.split("\\s*,\\s*")); backend = new BackendConnector(stats); subscriptionManager = new SubscriptionManager(backend); SeqNumManager sequencer = new SeqNumManager(); final NotificationManager nom = new NotificationManager(sequencer); cam = new ClientAuthenticationManager(subscriptionManager, nom, backend, sequencer); subscriptionManager.setClientAuthenticationManager(cam); // dump all notification info Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { // LOG.debug("Flushing print buffer..."); nom.dump(); subscriptionManager.dump(); } }, 0, 30000); StatsDumper dumper = new StatsDumper(); dumper.start(); backend.connect(properties, nodeArr, subscriptionManager, cam); FrontendServer frontend = new FrontendServer(properties, backend, stats, subscriptionManager, cam); LOG.debug("Gateway start-up complete."); } catch (IOException e) { LOG.error("Could not start server " + e.getMessage()); System.exit(1); } catch (URISyntaxException e) { LOG.error("Invalid host specification: " + e.getMessage()); System.exit(1); } catch (Exception e) { LOG.error("Could not start server " + e.getMessage()); e.printStackTrace(); } }
From source file:name.nirav.mp.service.analytics.EntityExtractionService.java
public EntityExtractionService(OpenCalaisConfig config, PredictionDB db) { this.config = config; this.calaisConfig = new CalaisConfig(); this.calaisConfig.set(CalaisConfig.ConnParam.READ_TIMEOUT, config.readTimeout); this.calaisConfig.set(CalaisConfig.ConnParam.CONNECT_TIMEOUT, config.readTimeout); this.db = db; this.client = new CalaisRestClient(config.licenseKey); this.rateLimiter = RateLimiter.create(4); Timer timer = new Timer("Calais-ban-reset"); timer.scheduleAtFixedRate(new TimerTask() { public void run() { LocalDateTime now = LocalDateTime.now(); if (now.getHour() >= 23) { LOG.info("It is close to midnight {}, resetting callCount", now.getHour()); callCount = 0;/* ww w . java 2 s.c o m*/ } } }, 1000, TimeUnit.MINUTES.toMillis(30)); }
From source file:org.hxzon.demo.jfreechart.PolarChartDemo.java
public PolarChartDemo(String title) { super(title); PolarChartPanel chartPanel = new PolarChartPanel(polarChart1); //have a bug after show tooltips // chartPanel.setHorizontalAxisTrace(true); // chartPanel.setVerticalAxisTrace(true); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); chartPanel.addMouseListener(new MyChartClickHandler(chartPanel)); chartPanel.setPreferredSize(new Dimension(500, 270)); getContentPane().add(chartPanel);/*from w w w. jav a 2 s. c om*/ getContentPane().add(new ChartComboBox(chartPanel), BorderLayout.SOUTH); Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { addValue(); } }, 0, 200); }
From source file:fr.aliasource.webmail.proxy.impl.TimeOutMap.java
/** * @param timeout// ww w . java2 s. c o m * unused elements timeout in milliseconds */ public TimeOutMap(long timeout) { map = Collections.synchronizedMap(new HashMap<K, TimedItem<V>>()); this.timeout = timeout; executor = Executors.newFixedThreadPool(4); Timer t = new Timer(); t.scheduleAtFixedRate(new Remover(), 1000, timeout); }
From source file:DynamiskDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title./* ww w . j a va 2 s . com*/ */ public DynamiskDemo2(final String title) { super(title); this.series = new XYSeries(title, false, false); final XYSeriesCollection dataset = new XYSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JButton button = new JButton("Add New Data Item"); button.setActionCommand("ADD_DATA"); button.addActionListener(this); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); content.add(button, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); String fil = "C:" + File.separator + "Users" + File.separator + "madso" + File.separator + "Documents" + File.separator + "!Privat" + File.separator + "DTU 2016-2020" + File.separator + "MATLAB"; String filnavn = "EKGdata"; try { Scanner sc = new Scanner(new FileReader(fil + File.separator + filnavn)); Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { if (sc.hasNext()) { final double newItem = Double.parseDouble(sc.next()); series.add(x, newItem); x += 10; } } }, 100, 2); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.edmunds.etm.agent.impl.TcpHealthCheck.java
@Override public void execute(HealthCheckListener listener) { // Ensure that the listener is set Validate.notNull(listener, "Health check listener is null"); healthCheckListener = listener;/*from w ww . ja v a 2 s . c o m*/ // Initialize time values elapsedTime = 0; lastCheckTime = new Date().getTime(); // Schedule the initial health check Timer timer = new Timer(); timer.scheduleAtFixedRate(new HealthCheckTask(timer), interval, interval); if (logger.isInfoEnabled()) { InetAddress addr = getHostAddress(); String message = String.format("Health check started for host %s on port %d", addr.getHostAddress(), port); logger.info(message); } }
From source file:com.github.woonsan.commons.scxml.examples.stopwatch.StopWatchFrame.java
private void initUI() { JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); setContentPane(mainPanel);/* ww w.j a v a2 s . c om*/ JPanel contentPanel = new JPanel(); contentPanel.setLayout(new FlowLayout()); displayLabel = new JLabel("0:00:00,000"); contentPanel.add(displayLabel, BorderLayout.CENTER); mainPanel.add(contentPanel, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); startButton = createButton("START", "Start"); buttonPanel.add(startButton); stopButton = createButton("STOP", "Stop"); stopButton.setEnabled(false); buttonPanel.add(stopButton); resetButton = createButton("RESET", "Reset"); resetButton.setEnabled(false); buttonPanel.add(resetButton); mainPanel.add(buttonPanel, BorderLayout.SOUTH); pack(); setLocation(200, 200); setSize(260, 80); setResizable(true); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); Timer displayTimer = new Timer(); displayTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { displayLabel.setText(stopWatch.getDisplay()); } }, 100, 100); }
From source file:org.apache.camel.component.timer.TimerConsumer.java
protected void configureTask(TimerTask task, Timer timer) { if (endpoint.isFixedRate()) { if (endpoint.getTime() != null) { timer.scheduleAtFixedRate(task, endpoint.getTime(), endpoint.getPeriod()); } else {/* www .jav a 2s . c om*/ timer.scheduleAtFixedRate(task, endpoint.getDelay(), endpoint.getPeriod()); } } else { if (endpoint.getTime() != null) { if (endpoint.getPeriod() > 0) { timer.schedule(task, endpoint.getTime(), endpoint.getPeriod()); } else { timer.schedule(task, endpoint.getTime()); } } else { if (endpoint.getPeriod() > 0) { timer.schedule(task, endpoint.getDelay(), endpoint.getPeriod()); } else { timer.schedule(task, endpoint.getDelay()); } } } }