List of usage examples for java.util.concurrent TimeUnit SECONDS
TimeUnit SECONDS
To view the source code for java.util.concurrent TimeUnit SECONDS.
Click Source Link
From source file:Main.java
public static void main(String[] args) { try {/* ww w. j a v a 2 s . c o m*/ System.out.println("sleep for 5 seconds."); TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); // The "main" thread will sleep System.out.println("woke up."); } catch (InterruptedException e) { System.out.println("interrupted."); } System.out.println("done."); }
From source file:PoolSize.java
public static void main(String[] args) { ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 20, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); System.out.println(executor.getPoolSize()); }
From source file:Main.java
public static void main(String args[]) { ScheduledThreadPoolExecutor stpe = new ScheduledThreadPoolExecutor(5); stpe.scheduleAtFixedRate(new Job1(), 0, 5, TimeUnit.SECONDS); stpe.scheduleAtFixedRate(new Job2(), 1, 2, TimeUnit.SECONDS); }
From source file:Main.java
public static void main(String args[]) { CountDownLatch cdl = new CountDownLatch(5); System.out.println(cdl.getCount()); new MyThread(cdl); try {/*from w w w. j a v a2s . co m*/ cdl.await(100, TimeUnit.SECONDS); } catch (InterruptedException exc) { System.out.println(exc); } System.out.println("Done"); }
From source file:Main.java
public static void main(String args[]) { CountDownLatch cdl = new CountDownLatch(5); System.out.println(cdl.getCount()); new MyThread(cdl); try {/*w w w .j a va2 s . co m*/ cdl.await(100, TimeUnit.SECONDS); } catch (InterruptedException exc) { System.out.println(exc); } System.out.println(cdl.toString()); }
From source file:Main.java
public static void main(String[] args) { for (int i = 0; i < 200; i++) Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new Main(), 1, 10, TimeUnit.SECONDS); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { Main task = new Main(); int threads = Runtime.getRuntime().availableProcessors(); ExecutorService pool = Executors.newFixedThreadPool(threads); for (int i = 0; i < threads; i++) { pool.submit(task);//from w ww . j av a2 s. com } pool.awaitTermination(120, TimeUnit.SECONDS); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { runThreadUseLambda();/*from w ww . j a va2 s. co m*/ runThreadUseInnerClass(); TimeUnit.SECONDS.sleep(1); }
From source file:Main.java
public static void main(String[] args) throws Exception { BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<Runnable>(48); ThreadPoolExecutor testExecutor = new ThreadPoolExecutor(6, 10, 1, TimeUnit.SECONDS, blockingQueue); List<Future<String>> futures = new ArrayList<>(); for (int i = 0; i < 20; i++) { Future<String> testFuture = testExecutor.submit(new MyCallable(i)); futures.add(testFuture);//ww w. j av a 2 s. c om } for (Future<String> testFuture : futures) { System.out.println("Output Returned is : " + testFuture.get()); } }
From source file:Main.java
public static void main(String args[]) { executor = Executors.newScheduledThreadPool(1); runnable = new Runnable() { @Override//from w w w .j ava 2 s .com public void run() { System.out.println("Inside runnable" + i++); } }; future = executor.scheduleWithFixedDelay(runnable, 0, 2, TimeUnit.SECONDS); try { Thread.sleep(4000); // sleeping for 2 seconds } catch (InterruptedException e) { e.printStackTrace(); } future.cancel(false); future = executor.scheduleWithFixedDelay(runnable, 0, 10, TimeUnit.SECONDS); }