java.util.Timer.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中java.util.Timer.<init>()方法的一些代码示例,展示了Timer.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timer.<init>()方法的具体详情如下:
包路径:java.util.Timer
类名称:Timer
方法名:<init>

Timer.<init>介绍

[英]Creates a new non-daemon Timer.
[中]创建一个新的非守护进程计时器。

代码示例

代码示例来源:origin: stackoverflow.com

class SayHello extends TimerTask {
  public void run() {
    System.out.println("Hello World!"); 
  }
}

// And From your main() method or any other method
Timer timer = new Timer();
timer.schedule(new SayHello(), 0, 5000);

代码示例来源:origin: pedrovgs/AndroidWiFiADB

public void run() {
  new Timer().schedule(new TimerTask() {
   @Override public void run() {
    boolean refreshRequired = androidWifiADB.refreshDevicesList();
    if (refreshRequired) {
     updateUi();
    }
   }
  }, 0, INTERVAL_REFRESH_DEVICES);
 }
});

代码示例来源:origin: apache/storm

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

代码示例来源:origin: stackoverflow.com

System.out.println("Generating report");
Timer timer = new Timer();
Calendar date = Calendar.getInstance();
date.set(
date.set(Calendar.MILLISECOND, 0);
timer.schedule(
 new ReportGenerator(),
 date.getTime(),

代码示例来源:origin: stackoverflow.com

Timer timer = new Timer();
TimerTask task = new TimerTask() {
  @Override
  public void run() {
    System.out.println(System.currentTimeMillis());
  }
};
timer.scheduleAtFixedRate(task, 0, 1000);

代码示例来源:origin: stackoverflow.com

@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();

代码示例来源:origin: apache/metron

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

代码示例来源:origin: stackoverflow.com

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;

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: fossasia/neurolab-desktop

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: redisson/redisson

/**
 * Schedules prune.
 */
public void schedulePrune(long delay) {
  if (pruneTimer != null) {
    pruneTimer.cancel();
  }
  pruneTimer = new Timer();
  pruneTimer.schedule(
      new TimerTask() {
        @Override
        public void run() {
          prune();
        }
      }, delay, delay
  );
}

代码示例来源:origin: apache/hive

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

代码示例来源:origin: facebook/facebook-android-sdk

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: openmrs/openmrs-core

GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
frame = new JFrame();
Window window = new Window(frame);
frame.setVisible(true);
new Timer().schedule(later, 500);
new Timer().schedule(laterStill, 10000);
window.setVisible(false);
frame = null;

代码示例来源:origin: javamelody/javamelody

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

代码示例来源:origin: stackoverflow.com

static int cnt=0;
public ArrayList<RadioButton> buttonArray = new ArrayList<RadioButton>();
private Timer timer = new Timer(); 
      timer.schedule(new MyTimerTask(), 1000,2000);
    System.out.println(cnt);

代码示例来源:origin: stackoverflow.com

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

相关文章