Ask Experts Questions for FREE Help !
Ask
    nishu3389's Avatar
    nishu3389 Posts: 1, Reputation: 1
    New Member
     
    #1

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

Check out some similar questions!

Two threads call a static method? Is this a problem? [ 0 Answers ]

If two threads call a static void in another class what happens? Will the class pick one to do first or completely forget about the other one?

How to open one Jframe from main method call [ 0 Answers ]

I have downloaded a snake game project in java. Initially the project contains three java files i.e " Engine.java Snake.java GameBoard.java And Engine.java have the main() method, when i run this Engine.java class game starts running.

How do I calculate gross profit using the weighted average method and the FIFO method [ 0 Answers ]

Please give me the fomular and where to look, which amounts


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.