sergAccount

Untitled

Feb 13th, 2021
681
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.app12;
  7.  
  8. import java.util.concurrent.Executors;
  9. import java.util.concurrent.ScheduledExecutorService;
  10. import java.util.concurrent.TimeUnit;
  11.  
  12. /**
  13.  *
  14.  * @author Admin
  15.  */
  16. public class Main {
  17.     //
  18.     public static void doIt() {
  19.         System.out.println("doIt!!!!!!!!!!!!!!!!!!!!!!");
  20.     }
  21.     //
  22.     public static void main(String[] args) {
  23.         // для выполнения период задачи (через определенной интервал времени)
  24.         ScheduledExecutorService service = Executors.newScheduledThreadPool(2);
  25.         // настраиваем запуск задачи типа Task с периодом 10 секунд (ждем 5 сек для запуска первой задачи)
  26.         //service.scheduleAtFixedRate(new Task(), 5, 10, TimeUnit.SECONDS);
  27.         // lambda          
  28.         service.scheduleAtFixedRate(() -> {System.out.println("MY TASK!!!");} , 5, 10, TimeUnit.SECONDS);
  29.         // ссылка на метод: ::
  30.         service.scheduleAtFixedRate(Main::doIt, 5, 10, TimeUnit.SECONDS);        
  31.     }    
  32. }
  33.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×