Example usage for java.util.concurrent TimeUnit MILLISECONDS

List of usage examples for java.util.concurrent TimeUnit MILLISECONDS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit MILLISECONDS.

Prototype

TimeUnit MILLISECONDS

To view the source code for java.util.concurrent TimeUnit MILLISECONDS.

Click Source Link

Document

Time unit representing one thousandth of a second.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.from(time, TimeUnit.MILLISECONDS);
    System.out.println(fileTime);

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);

    FileTime fileTime1 = FileTime.from(time, TimeUnit.MILLISECONDS);

    System.out.println(fileTime.compareTo(fileTime1));

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);

    FileTime fileTime1 = FileTime.from(time, TimeUnit.MILLISECONDS);

    System.out.println(fileTime.equals(fileTime1));

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(600, 400);//from   w w  w. j a v  a  2s  .c  o m
    frame.setVisible(true);
    Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> {
        System.out.println(frame.getLocation());
    }, 0, 1000, TimeUnit.MILLISECONDS);
}

From source file:MainClass.java

public static void main(String[] args) {
    int nTasks = 5;
    long n = 1000L;
    int tpSize = 10;

    ThreadPoolExecutor tpe = new ThreadPoolExecutor(tpSize, tpSize, 50000L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());

    Task[] tasks = new Task[nTasks];
    for (int i = 0; i < nTasks; i++) {
        tasks[i] = new Task(n, "Task " + i);
        tpe.execute(tasks[i]);// w  w  w.  j a  va 2s.  c o m
    }
    tpe.shutdown();
}

From source file:Main.java

public static void main(String[] args) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(2);
    scheduledThreadPoolExecutor.scheduleAtFixedRate(() -> {

        throw new RuntimeException(" scheduleAtFixedRate test ScheduledThreadPoolExecutor");
    }, 0, 3000, TimeUnit.MILLISECONDS);

    scheduledThreadPoolExecutor.scheduleAtFixedRate(() -> {

        System.out.println("scheduleAtFixedRate: " + LocalDateTime.now().format(formatter));
    }, 0, 2000, TimeUnit.MILLISECONDS);

    scheduledThreadPoolExecutor.schedule(() -> {

        System.out.println("schedule");
    }, 1, TimeUnit.SECONDS);//  www .j  a  va2  s  . c o m
}

From source file:Test.java

public static void main(String[] args) throws InterruptedException {
    BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
    for (int i = 0; i < 10; i++) {
        final int localI = i;
        queue.add(new Runnable() {
            public void run() {
                doExpensiveOperation(localI);
            }/*from   w ww. ja v  a  2  s  .  c o m*/
        });
    }
    ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 1000, TimeUnit.MILLISECONDS, queue);
    executor.prestartAllCoreThreads();
    executor.shutdown();
    executor.awaitTermination(100000, TimeUnit.SECONDS);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(200, 300);//from  w  w  w . jav a 2 s  .  c om
    PaintSurface canvas = new PaintSurface();

    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3);
    executor.scheduleAtFixedRate(canvas, 0L, 100L, TimeUnit.MILLISECONDS);

    f.add(canvas);
    f.setVisible(true);
}

From source file:BallRoom.java

public static void main(String[] a) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(200, 300);//ww w  .  j a v  a  2s.com
    PaintSurface canvas = new PaintSurface();

    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3);
    executor.scheduleAtFixedRate(canvas, 0L, 100L, TimeUnit.MILLISECONDS);

    f.getContentPane().add(canvas);
    f.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    System.out.println("Thread pool size = " + MAX_THREADS);
    ExecutorService executor = Executors.newFixedThreadPool(MAX_THREADS);
    Future previousFuture = null;
    for (int i = 0; i < MAX_THREADS; i++) {
        JobRunnable job = new JobRunnable(i, previousFuture);
        previousFuture = executor.submit(job);
    }//from w  ww.j av  a2 s . c  om
    executor.shutdown();
    executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
    System.out.println("Program done.");
}