Skip to content

Instantly share code, notes, and snippets.

View addo47's full-sized avatar
🏠
Working from home

Abbas Abou Daya addo47

🏠
Working from home
  • Gearlay
  • Vancouver, BC
View GitHub Profile
@Test
public void testReturnCodesTime() {
StopWatch watch = new StopWatch();
watch.start();
for (int i = 0; i <= 1000000; i++) {
if (doSomethingCodes(i) == -1)
watch.stop();
}
long returnCodesTime = watch.getLastTaskTimeMillis();
@addo47
addo47 / delay.java
Created April 17, 2017 14:32
Get delay from a certain time
Calendar calendar = Calendar.getInstance();
calendar.set(2017, Calendar.APRIL, 17, 6, 27, 0);
long desiredDelay = calendar.toInstant().getEpochSecond() - TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
Executors.newSingleThreadScheduledExecutor()
.schedule(() -> {/* your logic here */}, desiredDelay, TimeUnit.SECONDS);