Skip to Main Content

How do I implement a Timed thread in Java 8?

3192389Mar 7 2016 — edited Apr 13 2016

Hello,

I hope this is the correct forum.  (Java 8?)

Anyway, how would I start to implement this code with Java 8:

    public static void main(String[] args) {
                   
        Wait wait = new Wait(10000); //wait for ten seconds

        try
        {
            wait.StartWait(); //return immediately
            Thread.sleep(11000);
            wait.StopWait();
        }
        catch (Exception ex)
        {
            System.out.print("Timer timed out.");
        }

        System.out.print("Success!");       
    }

Again, I need to return immediately from the StartWait method.

Thank you.

williamj

This post has been answered by Arpit1992 on Apr 13 2016
Jump to Answer
Comments
Post Details
Added on Mar 7 2016
3 comments
1,261 views