Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Can I call Thread.currentThread().sleep() method into another user defined method (https://www.askmehelpdesk.com/showthread.php?t=811560)

  • May 9, 2015, 04:30 AM
    nishu3389
    Can I call Thread.currentThread().sleep() method into another user defined method
    I want to print something in 2 sec. intervals for this I am using thread,
    I am calling sleep() in another gap() method and calling gap() to wherever I want,
    but its not print in desired interval , what's wrong

    here is the code

    public void gap(){
    try {
    Thread.currentThread().sleep(3);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    for(int I=1;i<=5;i++){
    System.out.println(".");
    try {
    Thread.currentThread().sleep(1);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    public static void main(String[] args) {
    ArrayListDemo obj=new ArrayListDemo();
    obj.gap();
    }

  • All times are GMT -7. The time now is 12:50 AM.