/** * Start the timer to run at fixed intervals. */ @Override public void start() { rotationTimer = new Timer(true); TimerTask task = new TimerTask() { @Override public void run() { rotationTimerTriggered.set(true); } }; rotationTimer.scheduleAtFixedRate(task, interval, interval); }
Timer timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { System.out.println(System.currentTimeMillis()); } }; timer.scheduleAtFixedRate(task, 0, 1000);
@Override public void run() { System.out.println(new Date() + " running ..."); timer = new Timer(); timer.schedule(new EchoTask(), 0, 1000); System.out.println("initializing ..."); System.out.println("starting ..."); main(null); System.out.println("stopping ..."); if (timer != null) { timer.cancel();
System.out.println("Consumer Group: " + groupId); kafkaConfig.put(ConsumerConfig.GROUP_ID_CONFIG, groupId); if(LoadOptions.KAFKA_CONFIG.has(cli)) { System.out.println("Thread pool size: " + numThreads); pool = Executors.newFixedThreadPool(numThreads); Optional<Object> eps = evaluatedArgs.get(LoadOptions.EPS); long monitorDelta = (long) evaluatedArgs.get(LoadOptions.MONITOR_DELTA).get(); if((eps.isPresent() && outputTopic.isPresent()) || monitorTopic.isPresent()) { Timer timer = new Timer(false); long startTimeMs = System.currentTimeMillis(); if(outputTopic.isPresent() && eps.isPresent()) { List<String> templates = (List<String>)evaluatedArgs.get(LoadOptions.TEMPLATE).get(); if(templates.isEmpty()) { System.out.println("Empty templates, so nothing to do."); return; System.out.println("Generating data to " + outputTopicStr + " at " + targetLoad + " events per second"); System.out.println("Sending " + messagesPerPeriod + " messages to " + outputTopicStr + " every " + sendDelta + "ms"); timer.scheduleAtFixedRate(new SendToKafka( outputTopicStr , messagesPerPeriod , numThreads
int delay = 1000; int period = 1000; timer = new Timer(); interval = Integer.parseInt(secs); System.out.println(secs); timer.scheduleAtFixedRate(new TimerTask() { System.out.println(setInterval()); timer.cancel(); return --interval;
timer = new Timer( delay, this); JFrame frame = new JFrame( "Double Click Test" ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.addMouseListener( new ClickListener() System.out.println("single"); System.out.println("double"); frame.setVisible(true);
int[] y1 = new int[numChannels]; frame = new JFrame() { buttonCollect.setPreferredSize(new Dimension(100, 30)); buttonCollect.setEnabled(false); buttonBase.setPreferredSize(new Dimension(100, 30)); buttonBase.setEnabled(true); buttonBase.addActionListener(new ActionListener() { buttonTrain.setPreferredSize(new Dimension(100, 30)); buttonTrain.setEnabled(false); buttonTrain.setBackground(Color.cyan.darker()); frame.setSize(width - samplesPerSecond-(drawBins?0:600), height); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); System.out.println("promode:" + this.proMode); buttonFrame = new JFrame(); buttonFrame.setLayout(new BorderLayout()); buttonFrame.setSize(width, 100); timer = new Timer(); try { Thread.sleep(300);
import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Test { public static void main(String[] args) { JFrame f = new JFrame(); final JDialog dialog = new JDialog(f, "Test", true); Timer timer = new Timer(2000, new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); dialog.dispose(); } }); timer.setRepeats(false); timer.start(); dialog.setVisible(true); // if modal, application will pause here System.out.println("Dialog closed"); } }
private final Timer timer = new Timer(1000, this); private final JLabel text = new JLabel(); JFrame f = new JFrame(); setTranslucency( f ); f.setUndecorated( true ); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setBackground(new Color(0f, 0f, 0f, 1f / 3f)); f.add(new Translucent()); f.pack(); f.setVisible(true);
public void go() { LOG.info("Running ReporterTask every " + notificationInterval + " miliseconds."); rpTimer = new Timer(true); ReporterTask rt = new ReporterTask(reporter); rpTimer.scheduleAtFixedRate(rt, 0, notificationInterval); if (timeout > 0) { srpTimer = new Timer(true); StopReporterTimerTask srt = new StopReporterTimerTask(rt); srpTimer.schedule(srt, timeout); } } }
@Override public void run() { try { if (indexingTimer != null) { indexingTimer.cancel(); } previousDigest = null; indexingTimer = new Timer(); indexingTimer.scheduleAtFixedRate( indexingTask, 0, Constants.APP_INDEXING_SCHEDULE_INTERVAL_MS ); } catch (Exception e) { Log.e(TAG, "Error scheduling indexing job", e); } } });
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Timer timer = new Timer(1000, (ActionEvent e) -> { frame.setTitle(String.valueOf(System.currentTimeMillis())); }); timer.setRepeats(true); timer.start(); frame.setVisible(true);
private void mergeData() throws IOException { final Timer timer = new Timer("javamelody-datamerge", true); try { JRobin.initBackendFactory(timer); final List<File> directories = new ArrayList<>(listFiles(storageDirectory)); for (final Iterator<File> it = directories.iterator(); it.hasNext();) { if (!it.next().isDirectory()) { it.remove(); } } if (directories.isEmpty()) { throw new IllegalArgumentException( "No subdirectories found in " + storageDirectory); } mergeDirectories(directories); } finally { timer.cancel(); } }
public static void main(String args[]) { int period = 2000; int delay = 2000; Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { // Variables as member variables instead of local variables in main() private double lastPrice = 0; private Price priceObject = new Price(); private double price = 0; public void run() { price = priceObject.getNextPrice(lastPrice); System.out.println(); lastPrice = price; } }, delay, period); }