Java 8 Timer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Timer class.

This code example shows how to use the following methods:
 
    private void createIndexTimer(Properties properties) throws JMException {
 
        //instantiate, register and start the Timer service 
        ObjectName timer = new ObjectName("service:name=timer");
        server.registerMBean(new Timer(), timer);
        server.invoke(timer, "start", null, null);
        log.info("Started timer service");
 
        boolean enabled = Boolean.parseBoolean(properties.getProperty("org.opensolaris.opengrok.management.indexer.enabled"));
        int period = Integer.parseInt(properties.getProperty("org.opensolaris.opengrok.management.indexer.sleeptime"));
        log.fine("Indexer enabled: " + enabled);
        log.fine("Indexer period: " + period + " seconds");
        //instantiate and register resource purger 
        ObjectName indexRunner = new ObjectName("OGA:name=AgentIndexRunner," + "source=timer");
        server.registerMBean(AgentIndexRunner.getInstance(enabled), indexRunner);
        // Add index notification to timer (read from org.opensolaris.opengrok.management.indexer.sleeptime property). 
        Date date = new Date(System.currentTimeMillis() + Timer.ONE_SECOND * 5);
        Long longPeriod = Long.valueOf(period * Timer.ONE_SECOND);
        Integer id = (Integer) server.invoke(timer, "addNotification",
6
CodeRank
This code example shows how to use the following methods:addNotification, removeNotifications, start, stop
            stopUpdates(); 
    } 
 
    public synchronized void startUpdates() { 
        if (!timerStarted) {
            timer.addNotification("tickTimer", null, null, new Date(System.currentTimeMillis()), timerPeriod);
            this.timerStarted = true;
            timer.start();
        } 
    } 
 
    public synchronized void stopUpdates() { 
        if (timerStarted) {
            try { 
                timer.removeNotifications("tickTimer");
                this.timerStarted = false;
            } catch (InstanceNotFoundException ex) {
            } 
            timer.stop();
        } 

5
CodeRank
See Code Examples for Java 8 Timer Methods: