简体   繁体   中英

Using Timer.schedule() with Milliseconds in Java

I am trying to run a Timer to execute a lambda expression 1.8 seconds in the future.

private static Timer obRunTime = new Timer();

public static void main( String[] args )
{
    obRunTime.schedule(() -> {
    }, 1.8);
}

The problem here is .schedule can't take in a double. Is there a way I can cast it so the schedule will run for 1800 milliseconds or even a way I can take in 1.8 seconds?

 Timer obRunTime = new Timer();
        obRunTime.schedule(new TimerTask() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            System.out.println("will be printed after 5 seconds");
        }
    },5000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM