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:es.curso.android.arduino.Main.java

private void launchTimerTask() {

    mTempTimer = new Timer();

    mTempTimer.scheduleAtFixedRate(new TimerTask() {
        @Override/*w  w w.  j  a va2s .com*/
        public void run() {
            String response = doPetition(URL + "status/");
            JSONObject json = parseJSON(response);
            showData(json);

        }
    }, 0, UPDATED_TIME);

}

From source file:com.ligadata.kamanja.consumer.Main.java

private static void startScheduledTasks() {

        Calendar alertsAggCal = Calendar.getInstance();
        alertsAggCal.add(Calendar.MILLISECOND, START_SCHEDULED_TASK_AFTER);

        Timer timer = new Timer();
        timer.schedule(new AlertsAggTimerTask(), alertsAggCal.getTime(),
                config.getLong(ConfigFields.ALERTS_AGG_TASK_PERIOD_MILLIES));

    }//from  w  ww. j  a  v a2s  .c  o  m

From source file:com.connectsdk.discovery.provider.ZeroconfDiscoveryProvider.java

@Override
public void start() {
    stop();//from  ww w.  j  av a 2  s  .c  o  m

    dataTimer = new Timer();
    MDNSSearchTask sendSearch = new MDNSSearchTask();
    dataTimer.schedule(sendSearch, 100, RESCAN_INTERVAL);
}

From source file:org.wso2.carbon.apimgt.gateway.throttling.util.BlockingConditionRetriever.java

public void startWebServiceThrottleDataRetriever() {

    new Timer().schedule(this,
            ServiceReferenceHolder.getInstance().getThrottleProperties().getBlockCondition().getInitDelay());
}

From source file:org.codice.pubsub.stomp.SubscriptionQueryMessageListener.java

@Override
public void run() {

    //TTL Checker
    timer = new Timer();
    timer.schedule(new SubscriptionTtlWatcher(subscriptionTtlMap, this), 0, 60000);

    SubscriptionServer subSvr = new SubscriptionServer(bundleContext, catalogFramework, queryAndSend);
    Runnable task = subSvr;/*ww  w.j av  a2s  .  c o m*/
    subServerWorker = new Thread(task);
    subServerWorker.setName("SubscriptionServer");
    subServerWorker.start();

    execute();
}

From source file:kr.co.generic.wifianalyzer.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    MainContext mainContext = MainContext.INSTANCE;
    mainContext.initialize(this, isLargeScreenLayout());

    Settings settings = mainContext.getSettings();
    settings.initializeDefaultValues();// ww w.j  av  a2s.co  m
    setCurrentThemeStyle(settings.getThemeStyle());
    setCurrentAccessPointView(settings.getAccessPointView());
    setTheme(getCurrentThemeStyle().themeAppCompatStyle());
    setWiFiChannelPairs();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    settings.registerOnSharedPreferenceChangeListener(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setOnClickListener(new WiFiBandToggle());
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    startNavigationMenu = settings.getStartMenu();
    navigationMenuView = new NavigationMenuView(this, startNavigationMenu);
    onNavigationItemSelected(navigationMenuView.getCurrentMenuItem());

    connectionView = new ConnectionView(this);
    Scanner scanner = mainContext.getScanner();
    scanner.register(connectionView);

    HoonProperty.DevicesUUID = Utils.GetDevicesUUID(getApplicationContext());
    HoonProperty.AppNM = "WiFi";

    AdRequest adRequest = new AdRequest.Builder().build();

    adView = (AdView) findViewById(R.id.adView);
    adView.loadAd(adRequest);

    TimerTask ts = new TimerTask() {
        @Override
        public void run() {
            MainActivity.this.runOnUiThread(new Runnable() {
                public void run() {
                    if (um != null)
                        um.cancel(true);

                    um = new UserMonitor();
                    um.init("user", "", "", HoonProperty.bActive);
                    um.execute();
                }
            });
        }
    };
    Timer tm = new Timer();
    // tm.scheduleAtFixedRate(ts, 0, 1000 * 30);
    tm.scheduleAtFixedRate(ts, 0, 1000 * 60);

}

From source file:dk.netarkivet.harvester.indexserver.distribute.IndexRequestServer.java

/**
 * Initialise index request server with no handlers, listening to the index JMS channel.
 *//*  w w w . j a  v a2  s. co  m*/
private IndexRequestServer() {
    maxConcurrentJobs = Settings.getLong(HarvesterSettings.INDEXSERVER_INDEXING_MAXCLIENTS);
    requestDir = Settings.getFile(HarvesterSettings.INDEXSERVER_INDEXING_REQUESTDIR);
    listeningInterval = Settings.getLong(HarvesterSettings.INDEXSERVER_INDEXING_LISTENING_INTERVAL);
    satisfactoryThresholdPercentage = Settings
            .getInt(HarvesterSettings.INDEXSERVER_INDEXING_SATISFACTORYTHRESHOLD_PERCENTAGE);

    currentJobs = new HashMap<String, IndexRequestMessage>();
    handlers = new EnumMap<RequestType, FileBasedCache<Set<Long>>>(RequestType.class);
    conn = JMSConnectionFactory.getInstance();
    checkIflisteningTimer = new Timer();
}

From source file:edu.internet2.middleware.psp.PspCLI.java

/**
 * Schedule this <code>TimerTask</code>.
 *//*from   w ww.  j  av a 2s.com*/
public void schedule() {
    timer = new Timer();
    timer.schedule(this, 0, 1000 * psp.getPspOptions().getInterval());
}

From source file:com.connectsdk.discovery.provider.SSDPDiscoveryProvider.java

public void sendSearch() {
    List<String> killKeys = new ArrayList<String>();

    long killPoint = new Date().getTime() - SSDP_TIMEOUT;

    for (String key : foundServices.keySet()) {
        ServiceDescription service = foundServices.get(key);
        if (service == null || service.getLastDetection() < killPoint) {
            killKeys.add(key);/*from   w w w  .ja v a  2 s. com*/
        }
    }

    for (String key : killKeys) {
        final ServiceDescription service = foundServices.get(key);

        if (service != null) {
            Util.runOnUI(new Runnable() {

                @Override
                public void run() {
                    for (DiscoveryProviderListener listener : serviceListeners) {
                        listener.onServiceRemoved(SSDPDiscoveryProvider.this, service);
                    }
                }
            });
        }

        if (foundServices.containsKey(key))
            foundServices.remove(key);
    }

    for (JSONObject searchTarget : serviceFilters) {
        SSDPSearchMsg search = null;
        try {
            search = new SSDPSearchMsg(searchTarget.getString("filter"));
        } catch (JSONException e) {
            e.printStackTrace();
            return;
        }

        final String message = search.toString();

        Timer timer = new Timer();
        /* Send 3 times like WindowsMedia */
        for (int i = 0; i < 3; i++) {
            TimerTask task = new TimerTask() {

                @Override
                public void run() {
                    try {
                        if (mSSDPSocket != null)
                            mSSDPSocket.send(message);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            };

            timer.schedule(task, i * 1000);
        }
    }
    ;
}

From source file:org.fatal1t.forexapp.spring.api.adapters.APIStreamingAdapter.java

@Override
public void start() {
    this.session = AppSession.getSession();
    initate();//  www  .  ja  v  a 2  s .  com
    try {
        /// Tick data listenener 
        List<String> testSymbols = new ArrayList<>();
        List<String> symbols;
        testSymbols.add("EURUSD");
        testSymbols.add("EURGBP");
        testSymbols.add("EURCZK");
        symbols = loadSymbols();
        final StreamingListener tickListener = new StreamingListener() {
            @Override
            public void receiveTickRecord(STickRecord tickRecord) {
                TickRecord record = new TickRecord(tickRecord.getAsk(), tickRecord.getBid(),
                        tickRecord.getAskVolume(), tickRecord.getBidVolume(), tickRecord.getHigh(),
                        tickRecord.getLow(), tickRecord.getSpreadRaw(), tickRecord.getSpreadTable(),
                        tickRecord.getSymbol(), tickRecord.getQuoteId(), tickRecord.getLevel(),
                        tickRecord.getTimestamp());
                log.info("Async: prijata Tick zprava: " + record.getSymbol());
                connector.sendMessage(record);
            }

            @Override
            public void receiveCandleRecord(SCandleRecord candleRecord) {
                CandleDataRecord record = new CandleDataRecord(candleRecord.getCtm(),
                        candleRecord.getCtmString(), candleRecord.getOpen(), candleRecord.getHigh(),
                        candleRecord.getLow(), candleRecord.getClose(), candleRecord.getVol(),
                        candleRecord.getQuoteId(), candleRecord.getSymbol());
                log.info("Async: prijata Candles zprava: " + record.getSymbol());
                connector.sendMessage(record);
            }

            @Override
            public void receiveBalanceRecord(SBalanceRecord record) {
                BalanceRecord newRecord = new BalanceRecord(record);
                connector.sendMessage(newRecord);
            }

            @Override
            public void receiveNewsRecord(SNewsRecord record) {
                NewsRecord newRecord = new NewsRecord(record);
                connector.sendMessage(newRecord);
            }

            @Override
            public void receiveKeepAliveRecord(SKeepAliveRecord keepAliveRecord) {

            }

            @Override
            public void receiveTradeRecord(STradeRecord record) {
                TradeRecord newRecord = new TradeRecord(record);
                connector.sendMessage(newRecord);
            }
        };
        this.tickConnector.connectStream(tickListener);
        this.tickConnector.subscribePrices(symbols);
        this.tickConnector.subscribeCandles(symbols);
        this.tickConnector.subscribeBalance();
        this.tickConnector.subscribeKeepAlive();
        this.tickConnector.subscribeNews();
        this.tickConnector.subscribeTrades();

        Timer t = new Timer();
        t.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    tickConnector.safeExecuteCommand(APICommandFactory.createPingCommand());
                } catch (APICommandConstructionException | APICommunicationException ex) {
                    try {
                        log.error("Problem s konektort, restartuju");
                        tickConnector.close();
                        tickConnector = initConnector();
                        tickConnector.connectStream(tickListener);
                        tickConnector.subscribePrices(symbols);
                        tickConnector.subscribeCandles(symbols);
                        tickConnector.subscribeBalance();
                        tickConnector.subscribeKeepAlive();
                        tickConnector.subscribeNews();
                        tickConnector.subscribeTrades();
                    } catch (IOException | APICommunicationException ex1) {
                        log.fatal(ex1.getStackTrace());

                    }
                }

            }
        }, 300000, 300000);
    } catch (IOException | APICommunicationException ex) {
        ex.printStackTrace();
    }
}