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:emperior.Main.java

private static void makeContiniousCopys() {
    new Thread() {
        public void run() {
            final Timer timer = new Timer();
            TimerTask task = new TimerTask() {
                @Override//w  ww  .  j av a2s. c o  m
                public void run() {
                    if (mainFrame.actionPerformed) {
                        System.out.println("Mache nun Kopie vom aktuellen File");
                        int selection = mainFrame.jTabbedPane.getSelectedIndex();
                        String filePath = mainFrame.jTabbedPane.getToolTipTextAt(selection);

                        try {
                            copyFile(filePath, getTargetLocation());
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                    MainFrame.actionPerformed = false;
                }
            };
            timer.schedule(task, 0, 3000);
        }

    }.start();

}

From source file:org.jvnet.hudson.test.JenkinsRule.java

protected void setUpTimeout() {
    if (timeout <= 0) {
        System.out.println("Test timeout disabled.");
        return;/*w w  w . j a  v  a  2s  .  c om*/
    }
    final Thread testThread = Thread.currentThread();
    timeoutTimer = new Timer();
    timeoutTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            if (timeoutTimer != null) {
                LOGGER.warning(String.format("Test timed out (after %d seconds).", timeout));
                dumpThreads();
                testThread.interrupt();
            }
        }
    }, TimeUnit.SECONDS.toMillis(timeout));
}

From source file:com.xilinx.kintex7.MainScreen.java

public void startTimer() {
    timer = new java.util.Timer();
    timer.schedule(new TimerTask() {
        @Override//  www  .jav  a  2  s.  c  om
        public void run() {
            makeDMAData();
            updatePowerAndTemp();
        }
    }, 0, 3000);
}

From source file:com.sumzerotrading.broker.ib.InteractiveBrokersBroker.java

protected TimerTask getCurrencyOrderMonitor() {
    return new TimerTask() {
        @Override/*from   w  w  w .  j av a 2s  .  co m*/
        public void run() {
            processCurrencyOrders();
        }
    };
}

From source file:com.fluidops.iwb.api.ProviderServiceImpl.java

Timer scheduleProviders() {
    TimerTask timerTask = new TimerTask() {
        Queue<AbstractFlexProvider> queue = new ArrayBlockingQueue<AbstractFlexProvider>(10000);

        @Override/*  w  ww.jav  a2  s  . c o m*/
        public void run() {
            try {
                if (queue.isEmpty()) {
                    // add any work
                    for (AbstractFlexProvider s : getProviders()) {
                        if (s.pollInterval <= 0)
                            continue; // disabled 

                        if (s.running != null && s.running == true)
                            continue;

                        if (s instanceof ExternalProvider)
                            continue;

                        if (s instanceof LookupProvider)
                            continue;

                        if (s.lastUpdate == null)
                            queue.add(s);
                        else if (s.lastUpdate.getTime() + s.pollInterval < System.currentTimeMillis())
                            queue.add(s);
                    }
                }
                if (!queue.isEmpty()) {
                    AbstractFlexProvider provider = queue.poll();
                    runProvider(provider.providerID, null);
                }
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    };
    Timer timer = new Timer("IWB Provider Update");
    timer.schedule(timerTask, 1000, 1000);
    TimerRegistry.getInstance().registerProviderServiceTimer(timer);
    return timer;
}

From source file:com.atlauncher.data.Settings.java

public void startCheckingServers() {
    if (this.checkingServersTimer != null) {
        // If it's not null, cancel and purge tasks left
        this.checkingServersTimer.cancel();
        this.checkingServersTimer.purge(); // not sure if needed or not
    }//from ww  w  .ja va  2s.c  om

    if (this.enableServerChecker) {
        this.checkingServersTimer = new Timer();
        this.checkingServersTimer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                for (MinecraftServer server : checkingServers) {
                    server.checkServer();
                }
            }
        }, 0, this.getServerCheckerWaitInMilliseconds());
    }
}

From source file:org.apache.streams.elasticsearch.ElasticsearchPersistWriter.java

public void prepare(Object configurationObject) {
    this.veryLargeBulk = config.getBulk() == null ? Boolean.FALSE : config.getBulk();

    this.flushThresholdsRecords = config.getBatchSize() == null ? DEFAULT_BATCH_SIZE
            : (int) (config.getBatchSize().longValue());

    this.flushThresholdTime = config.getMaxTimeBetweenFlushMs() != null && config.getMaxTimeBetweenFlushMs() > 0
            ? config.getMaxTimeBetweenFlushMs()
            : DEFAULT_MAX_WAIT;//  w  ww.j av  a2 s.c  o  m

    this.flushThresholdBytes = config.getBatchBytes() == null ? DEFAULT_BULK_FLUSH_THRESHOLD
            : config.getBatchBytes();

    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            checkForFlush();
        }
    }, this.flushThresholdTime, this.flushThresholdTime);

}

From source file:com.game.simple.Game3.java

private static void startTimer() {
    t = new Timer();
    reconnect = new TimerTask() {

        @Override/*ww w  .j  a  v a2  s  .co m*/
        public void run() {
            Update();
            Log.e("--update--", "up");
        }
    };
    t.scheduleAtFixedRate(reconnect, 0, 5000);
}

From source file:gtu.jpa.hibernate.Rcdf002eDBUI.java

private JButton getJButton1x() {
    if (porcessDoAllBtn == null) {
        porcessDoAllBtn = new JButton();
        porcessDoAllBtn.setText("\u6392\u7a0b\u57f7\u884c");
        porcessDoAllBtn.setPreferredSize(new java.awt.Dimension(80, 54));
        porcessDoAllBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    String dateTime = processDoAllText.getText();
                    Validate.notBlank(dateTime, "");
                    Validate.isTrue(StringUtils.isNumeric(dateTime), "");
                    Validate.isTrue(StringUtils.isNumeric(dateTime), "");
                    Validate.isTrue(dateTime.length() == 14, "14");

                    SimpleDateFormat sdf = new SimpleDateFormat();
                    sdf.applyPattern("yyyyMMddHHmmss");
                    Date newDate = sdf.parse(dateTime);

                    Validate.isTrue(newDate.after(new Date()), "??");

                    setTitle(DateFormatUtils.format(newDate, "yyyy/MM/dd HH:mm:ss") + "?...");
                    Timer timer = new Timer();
                    timer.schedule(new TimerTask() {
                        @Override
                        public void run() {
                            oneClickDoAll();
                        }//from  w  w  w  .  jav  a 2s .  c  o m
                    }, newDate);
                } catch (Exception ex) {
                    JCommonUtil.handleException(ex);
                    setTitle("......" + ex.getMessage());
                }
            }
        });
    }
    return porcessDoAllBtn;
}

From source file:goo.TeaTimer.TimerActivity.java

/**
 * Starts the timer at the given time//w  w w.  j a va2  s  . c om
 * @param time with which to count down
 * @param service whether or not to start the service as well
 */
private void timerStart(int time, boolean service) {
    if (LOG)
        Log.v(TAG, "Starting the timer...");

    // Star external service
    enterState(RUNNING);

    if (service) {
        if (LOG)
            Log.v(TAG, "Starting the timer service ...");
        Intent intent = new Intent(getApplicationContext(), TimerReceiver.class);
        intent.putExtra("SetTime", mLastTime);
        mPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        mAlarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + time,
                mPendingIntent);
    }

    // Internal thread to properly update the GUI
    mTimer = new Timer();
    mTime = time;
    mTimer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            timerTic();
        }
    }, 0, TIMER_TIC);

    aquireWakeLock();
}