Results 1 to 5 of 5
  1. #1
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default static void sleep()

    According to the API specification the method sleep(long millis, int nanos) in the Thread class is overloaded, so that an long argument will execute the method with millis and and int argument will execute the sleep method with nanos. My question is, when I execute something like

    Java Code:
    Thread.currentThread().sleep(500);
    the value 500 is an int and the method should run with 500 nanos. But when I look at the behavior of the executed code the 500 are interpreted as millis. Does that mean that the 500 are interpreted as a long value?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: static void sleep()

    Huh? The overload you refer to takes two arguments.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default Re: static void sleep()

    Quote Originally Posted by DarrylBurke View Post
    Huh? The overload you refer to takes two arguments.
    Yes, this is the content and description of the sleep method in the java api 7. you must read it as either a long is passed OR a an int and not both! but the question is: a long argument will execute the method with millis and a call with an int argument will execute the sleep method with nanos. My question is, when I execute something like

    Thread.currentThread().sleep(500);

    the value 500 is an int and the method should run with 500 nanos. But when I look at the behavior of the executed code the 500 are interpreted as millis. Does that mean that the 500 are interpreted as a long value? Hope you get my question.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: static void sleep()

    There's only one overload of sleep(...) that takes a single argument, and that argument is of type long and represents a millisecond value.

    There is no overload of sleep(...) that takes a single int argument.

    There is an overload of sleep(...) that takes two arguments, a long that represents milliseconds and an int that represents nanoseconds.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

Similar Threads

  1. Q?> about public static void main(String args[])
    By boblingwide in forum New To Java
    Replies: 4
    Last Post: 03-23-2012, 11:17 AM
  2. Replies: 1
    Last Post: 12-04-2010, 05:41 PM
  3. Public static void main (String args[])
    By arefeh in forum New To Java
    Replies: 12
    Last Post: 01-28-2010, 11:58 AM
  4. Replies: 5
    Last Post: 01-24-2008, 11:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •