minor sandbox test for unfinished samples

This commit is contained in:
eugenp 2014-09-25 12:08:40 +03:00
parent 6e10b7d2d2
commit 2080f93e39
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package org.baeldung.java.sandbox;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import org.junit.Test;
public class SandboxJavaTest {
@Test
public void givenUsingTimer_whenSchedulingTaskOnce_thenCorrect() throws InterruptedException {
final Timer timer = new Timer("Thread's name");
System.out.println("Current time:" + new Date());
System.out.println("Thread name: " + Thread.currentThread().getName());
final TimerTask timerTask = new TimerTask() {
@Override
public void run() {
System.out.println("Time when task performed" + new Date());
System.out.println("Thread name: " + Thread.currentThread().getName());
timer.cancel();
}
};
final long delay = 2 * 1000;
timer.schedule(timerTask, delay);
}
}