Example usage for java.util Timer schedule

List of usage examples for java.util Timer schedule

Introduction

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

Prototype

public void schedule(TimerTask task, Date time) 

Source Link

Document

Schedules the specified task for execution at the specified time.

Usage

From source file:srvserver.thExecOTX.java

@Override
public void run() {
    System.out.println("Ejecutando OTX");
    Timer t1 = new Timer();

    t1.schedule(new task(), 20000);

}

From source file:srvserver.thExecOSP.java

@Override
public void run() {
    logger.info("Ejecutando OSP");

    //Recuperando los parametros de entrada
    String hostName;//from ww  w . j  a  v a 2s. c o m
    String ospName;

    Timer t1 = new Timer();
    t1.schedule(new task(), 40000);

}

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

public void afterPropertiesSet() throws Exception {
    Assert.notNull(id);/*from  ww  w.j  a va 2s  . c o  m*/
    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:$servicePackage$.$serviceImpl$ClientInvoker.java

public void afterPropertiesSet() throws Exception {
    Assert.notNull($serviceImplInstance$);
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override//from ww  w . ja v  a  2  s.  c  om
        public void run() {
            try {
                performRequest();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }

    }, delayBeforeSending);
}

From source file:org.eclipse.swordfish.samples.cxf.BookingServiceClientInvoker.java

public void afterPropertiesSet() throws Exception {
    Assert.notNull(bookingService);//from   w  w  w  .j a v  a2  s  .c  o m
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            try {
                performRequest();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }

    }, delayBeforeSending);
}

From source file:org.starfishrespect.myconsumption.server.business.Watcher.java

/**
 * Starts scheduling data retrieving//from w  w  w. j  a v  a  2  s  . c  o m
 */
@Override
public void run(String... args) throws Exception {
    retriever = new SensorsDataRetriever(mSensorRepository, mValuesRepository);
    statUpdater = new StatisticsUpdater(mSensorRepository, mPeriodStatRepository, mDayStatRepository);
    notifier = new Notifier(mApiKey, mSensorRepository, mPeriodStatRepository, mUserRepository);

    nextRetrieve = System.currentTimeMillis() + maxRetrieveInterval;

    Timer retrieveTimer = new Timer();
    retrieveTimer.schedule(new WatcherTask(), 0);

    Timer notificationSender = new Timer();
    notificationSender.schedule(new NotificationTask(), 0);
}

From source file:org.graylog.plugins.backup.strategy.AbstractMongoBackupStrategy.java

protected synchronized void processCommand(List<String> command) throws Exception {
    //need to find a a smart way to manage processBuilder

    ProcessBuilder pb = new ProcessBuilder(command);
    pb.redirectErrorStream(true);/*from w ww  .j  a v a 2 s  . co  m*/
    Process p = pb.start();

    Timer timeOut = new Timer();
    timeOut.schedule(new TimerTask() {
        @Override
        public void run() {
            if (p.isAlive()) {
                LOG.warn("restore process take more than 15 sec I'll destroy it");
                p.destroy();
            }
        }

        //this parameter need to be configurable

    }, 15000);

    p.waitFor();
    timeOut.cancel();

}

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   w ww  . j  a v a  2 s . c  o  m
    }

    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:com.willwinder.universalgcodesender.utils.ThreadHelperTest.java

@Test
public void waitUntilWhenChangeToTrueAfterTimeShouldReturnOk() throws TimeoutException {
    waitUntilCondition = false;/*  w  ww  . j  a  v  a2s . c o m*/

    // 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);
}

From source file:svc.managers.DemoManager.java

public List<DemoCitation> createCitationsAndViolations() {
    List<DemoCitation> demoCitations = new ArrayList<DemoCitation>();

    DemoUtilities demoUtilities = new DemoUtilities();
    List<Citation> citations = demoUtilities.generateRandomCitations();
    List<Violation> violations = demoUtilities.generateRandomViolations();

    mockCitationDataSource.insertCitations(citations);
    violationManager.insertViolations(violations);

    for (int citationCount = 0; citationCount < citations.size(); citationCount++) {
        Citation citation = citations.get(citationCount);
        int numberOfViolations = 0;
        for (int violationCount = 0; violationCount < violations.size(); violationCount++) {
            if (violations.get(violationCount).citation_number.equals(citation.citation_number)) {
                numberOfViolations++;//from  ww  w. j  ava 2s.c om
            }
        }
        DemoCitation demoCitation = new DemoCitation();
        demoCitation.citationNumber = citation.citation_number;
        demoCitation.dob = citation.date_of_birth;
        demoCitation.driversLicenseNumber = citation.drivers_license_number;
        Period daysTillCourt = DatabaseUtilities.getCurrentDate().until(citation.court_dateTime.toLocalDate());
        demoCitation.daysTillCourt = daysTillCourt.getDays();
        demoCitation.numberOfViolations = numberOfViolations;

        demoCitations.add(demoCitation);
    }

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            mockCitationDataSource.removeCitations(citations);
            violationManager.removeViolations(violations);
        }

    }, 60 * 60 * 1000);

    return demoCitations;
}