Question Detail

I want to make my thread to wait for 10 minutes. the thread will do nothing for 10 minutes.


Thread Reply

Anonymous

- 3 months ago

void threadExample() {
        Runnable gunnable = new Runnable() {
            public void run() {
                try {
//Thread Sleeping for 1sec 10times or you can sleep once for 10sec (10000 miliseconds= 10sec)
                    for (int i = 0; i < 100; i++) {
                        System.out.println("THreadXYZ " + i);
                        Thread.sleep(1000);
                    }
                } catch (InterruptedException e) {
                    //code to handle exception
                }
            }
        };
        // main code
        Thread t = new Thread(gunnable);
        t.start();
// using some action invoker, interrupt thread
        t.interrupt();
    }