Example usage for java.util TimerTask TimerTask

List of usage examples for java.util TimerTask TimerTask

Introduction

In this page you can find the example usage for java.util TimerTask TimerTask.

Prototype

protected TimerTask() 

Source Link

Document

Creates a new timer task.

Usage

From source file:jp.primecloud.auto.process.ProcessTimer.java

@Override
public void afterPropertiesSet() throws Exception {
    TimerTask timerTask = new TimerTask() {
        @Override//from ww  w.ja  v a  2s  .c  o m
        public void run() {
            try {
                processManager.process();
            } catch (Throwable e) {
                log.error(e.getMessage(), e);
            }
        }
    };
    timer = new Timer();
    timer.schedule(timerTask, 0, 15 * 1000);
}

From source file:org.duracloud.snapshot.service.impl.SnapshotFinalizerImpl.java

@Override
public void initialize(Integer pollingPeriodMs) {
    if (timer == null) {
        timer = new Timer();
        TimerTask task = new TimerTask() {
            /* (non-Javadoc)
             * @see java.util.TimerTask#run()
             *//*from   www  . j a  va  2s  .c  o m*/
            @Override
            public void run() {
                try {
                    log.info("launching periodic snapshot finalization...");
                    snapshotManager.finalizeSnapshots();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        };

        if (pollingPeriodMs == null || pollingPeriodMs < 1) {
            pollingPeriodMs = DEFAULT_POLLING_PERIOD_MS;
        }

        timer.schedule(task, new Date(), pollingPeriodMs);
        log.info("snapshot finalization scheduled to run every " + pollingPeriodMs + " milliseconds.");

    }

}

From source file:org.fusesource.cloudmix.agent.AgentPoller.java

public void start() throws Exception {
    timer = new Timer(true);
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            agentPoll();//  ww  w .  java  2 s .  c o m
        }
    }, initialPollingDelay, pollingPeriod);
}

From source file:com.zotoh.maedr.device.Poller.java

protected void onStart() throws Exception {
    _timer = new java.util.Timer(true);
    _timerTask = new TimerTask() {
        public void run() {
            try {
                wakeup();// ww  w  .  j  a  v  a2  s . c o  m
            } catch (Throwable t) {
                tlog().warn("", t);
            }
            return;
        }
    };

    schedule();
}

From source file:BufferedAnimate.java

public void go() {
    TimerTask task = new TimerTask() {
        public void run() {
            Color c = colors[0];/*from   w  ww . j a va  2s  . c o m*/
            synchronized (colors) {
                System.arraycopy(colors, 1, colors, 0, colors.length - 1);
                colors[colors.length - 1] = c;
            }
            repaint();
        }
    };
    Timer timer = new Timer();
    timer.schedule(task, 0, DELAY);
}

From source file:com.twosigma.beakerx.kernel.magic.command.functionality.MvnLoggerWidget.java

public MvnLoggerWidget(Message parentMessage) {
    this.widget = new BxHTML(parentMessage);
    this.timer = new Timer();
    this.timer.scheduleAtFixedRate(new TimerTask() {
        @Override//from  w  ww  . j  a  v a2s . c  om
        public void run() {
            if (jarNumbers > 0) {
                String info = getInfo(currentLine);
                String sizeWithUnit = byteCountToDisplaySize(new Double(sizeInKb * 1000).longValue());
                String status = String.format("%d jar%s, %s downloaded at %s %s", jarNumbers,
                        getPluralFormWhenNumberOfJarGreaterThanOne(), sizeWithUnit, speed, info);
                widget.setValue(status + "</br>" + formatCurrentLine());
                widget.setDomClasses(asList("text-ellipsis"));
            }
        }
    }, 0, PERIOD);
}

From source file:$servicePackage$.$serviceImpl$ClientInvoker.java

public void afterPropertiesSet() throws Exception {
    Assert.notNull($serviceImplInstance$);
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override/*from   w w w.j a  v  a2s. co m*/
        public void run() {
            try {
                performRequest();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }

    }, delayBeforeSending);
}

From source file:com.clustercontrol.accesscontrol.util.SessionTimer.java

/**
 * ??//  ww w . ja  v  a  2s. com
 * 
 * @param inverval ()
 */
public void start(final int interval) {
    // ???????
    if (m_timer == null && interval > 0) {
        // ?
        m_timer = new Timer(true);
        final ServiceContext context = ContextProvider.getContext();

        m_log.debug("SessionTimer start");

        // 
        m_timer.schedule(new TimerTask() {
            @Override
            public void run() {
                m_log.trace("SessionTimer start at Date : " + (new Date()).toString());
                ContextProvider.releaseContextHolder();
                ContextProvider.setContext(context);
                ClientSession.doCheck();
            }
        }, 1000, (long) interval * 60 * 1000);
    }
}

From source file:drusy.ui.panels.InternetStatePanel.java

public void updatePeriodically() {
    long delay = 1000 * 2;

    timer = new java.util.Timer();

    timer.scheduleAtFixedRate(new TimerTask() {
        @Override/*from   w  ww. j a  v a  2s.  co  m*/
        public void run() {
            update(fakeUpdater);
        }
    }, 0, delay);
}

From source file:com.entertailion.android.overlaynews.Downloader.java

public Downloader(Context context) {
    this.context = context;
    try {/*from  w  w w .j  a v  a 2  s.co m*/
        timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                if (System.currentTimeMillis() - updateTime > TIMER_REPEAT) {
                    getFeeds();
                }
            }
        }, 0, TIMER_REPEAT);
    } catch (Exception e) {
        Log.e(LOG_TAG, "Downloader timer", e);
    }
}