Created
May 8, 2018 15:37
-
-
Save yashk/cec29219c137cba30ba3a48a0c95fc2a to your computer and use it in GitHub Desktop.
Profiled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.Random; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.ScheduledExecutorService; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* Created by ykochare on 5/6/18. | |
*/ | |
public class Profiled { | |
public static void main(String[] args) { | |
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); | |
Runnable task = () -> { | |
try { | |
Random r = new Random(System.nanoTime()); | |
TimeUnit.SECONDS.sleep(2); | |
System.out.println("Scheduling: " + System.nanoTime()); | |
List<String> list = new ArrayList<>(); | |
for (int i=0;i<Math.abs(r.nextInt());i++){ | |
list.add(java.util.UUID.randomUUID().toString()); | |
} | |
Collections.shuffle(list,r); | |
Collections.sort(list); | |
} | |
catch (InterruptedException e) { | |
System.err.println("task interrupted"); | |
} | |
}; | |
executor.scheduleWithFixedDelay(task, 0, 1, TimeUnit.SECONDS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment