Example usage for java.util Timer Timer

List of usage examples for java.util Timer Timer

Introduction

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

Prototype

public Timer() 

Source Link

Document

Creates a new timer.

Usage

From source file:org.eclipse.swordfish.samples.configuration.ConfigurationProvider.java

public void afterPropertiesSet() throws Exception {
    Assert.notNull(id);/*from w w  w .ja  va2 s.c  om*/
    final Map<String, Object> configData = new HashMap<String, Object>();
    configData.put("testProperty1", "Updated by ConfigurationProvider");
    configData.put("currentDateTime", DateFormat.getDateTimeInstance().format(new Date()));
    LOG.info("Updating configuration");
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            swordfishContext.getConfigurationService().updateConfiguration(id, configData);

        }
    }, 5000);

}

From source file:be.fgov.kszbcss.rhq.websphere.component.server.log.xm4was.XM4WASLoggingProvider.java

public void start(ApplicationServer server, EventContext defaultEventContext, EventPublisher eventPublisher,
        String state) {/*from   ww  w .  ja v a 2  s. co  m*/
    timer = new Timer();
    dispatcher = new LogEventDispatcher(server,
            server.getMBeanClient("WebSphere:*,type=XM4WAS.LoggingService").getProxy(LoggingService.class),
            defaultEventContext, eventPublisher);
    if (state != null) {
        try {
            long sequence = Long.parseLong(state);
            if (log.isDebugEnabled()) {
                log.debug("Setting initial log sequence from persistent state: " + sequence);
            }
            dispatcher.setSequence(sequence);
        } catch (NumberFormatException ex) {
            log.error("Unable to extract log sequence from persistent state: " + state);
        }
    }
    timer.schedule(dispatcher, 30000, 30000);
}

From source file:BufferedAnimate.java

public void go() {
    TimerTask task = new TimerTask() {
        public void run() {
            Color c = colors[0];//from w  w w . j  av  a  2  s  . 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.example.customerservice.client.CustomerServiceTester.java

@Override
public void afterPropertiesSet() throws Exception {

    if (null == customerService) {
        System.out.println("Consumer is NULL!");
        return;/*from   ww w . jav  a  2  s.c  om*/
    }

    LocalTransportFactoryHolder.initSharedFactory(bus);
    System.out.println("*** Client: initialized with shared factory ***");
    System.out.println("Sending request for customers named Smith");

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            try {
                Customer customer = new Customer();
                customer.setName("Smith");
                customerService.updateCustomer(customer);
            } catch (Exception ex) {
                ex.printStackTrace();
                throw new RuntimeException(ex);
            }
        }
    }, 1000);
}

From source file:org.msjs.config.MsjsModule.java

/**
 * Constructs a guice module for msjs.//from www .j  a va  2  s  .  co  m
 *
 * @param config The configuration for the application.
 */
public MsjsModule(MsjsConfiguration config) {
    this.config = config;
    executorService = Executors.newCachedThreadPool();
    connectionManager = getConnectionManager();
    timer = new Timer();
}

From source file:org.ehcache.myapp.Main.java

public static void checkUpdates() {
    Timer timer = new Timer();
    timer.schedule(new Updater(), 1000, 120 * 1000);
}

From source file:Main.java

public TimedFutureTask(final Callable<Object> callable, final int timeoutMS) {
    timedCallable = (new Callable<Object>() {
        @Override/*from   ww w  .  j av  a 2 s. c o  m*/
        public Object call() throws Exception {
            cancelTimer = new Timer();
            cancelTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    f.cancel(true);
                }
            }, timeoutMS);
            final Object res = callable.call();
            cancelTimer.cancel();
            return res;
        }
    });
}

From source file:Main.java

public Main(int seconds) {
    timer = new Timer();
    timer.schedule(new RemindTask(), seconds * 1000);
}

From source file:Reminder.java

public Reminder(int seconds) {
    timer = new Timer();
    timer.schedule(new RemindTask(), seconds * 1000);
}

From source file:com.willwinder.universalgcodesender.utils.ThreadHelperTest.java

@Test
public void waitUntilWhenChangeToTrueAfterTimeShouldReturnOk() throws TimeoutException {
    waitUntilCondition = false;/*from   ww  w.  j  ava 2  s.  com*/

    // Start a timer that switches the condition after some time
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            waitUntilCondition = true;
        }
    }, 500);

    // Wait until the condition switches
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    ThreadHelper.waitUntil(() -> waitUntilCondition, 1000, TimeUnit.MILLISECONDS);
    stopWatch.stop();

    // Make sure it was within the time interval
    assertTrue(stopWatch.getTime() < 1000);
    assertTrue(stopWatch.getTime() >= 500);
}