Log in

View Full Version : Can I call Thread.currentThread().sleep() method into another user defined method


nishu3389
May 9, 2015, 04:30 AM
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();
}