Re: Help with Thread Sleep Calls causing lack of SLEEP

From: Jon Skeet (skeet_at_pobox.com)
Date: 11/19/03


Date: Wed, 19 Nov 2003 13:07:47 -0000

Alex Hunsley <lard@tardis.ed.ac.molar.uk> wrote:
> Are you sure you don't mean Thread.currentThread().sleep(3000)?

He certainly doesn't. sleep() is a static method. It's unfortunate that
Java allows static members to be accessed via references, but the above
does nothing different from Thread.sleep() - the current thread is
*always* the one which is set to sleep.
 
> Anyway, it sounds like you're using sleep for an evil purpose - i.e.
> waiting a random set amount of time for something else to finish - you
> should probably be using monitors or locking or something similar in
> this case.

Agreed.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Rationale for CS0536?
    ... >> current thread to sleep since Sleep is a static method. ... > design or even naming problem, nothing that would have to be ... Weren't you just asking why the compiler didn't let you call static methods ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Java Code Convention Guidelines question...
    ... The issue is invoking a static method while ... a different thread to sleep. ... confusion, by implying that the method "sleep" acted on a specific other ... about whether a developer should intentionally pretend to act on some ...
    (comp.lang.java.programmer)
  • Re: form object
    ... early on I thought about using a timer since a counter does not run ... concerned about the differing speeds on the various local workstations. ... any static method should probably be thread-aware; ... You don't want to Sleep(), as this will hang the UI thread (unless you spin ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: form object
    ... any static method should probably be thread-aware; when dealing with ... and push the method onto the owning UI's thread; ... You don't want to Sleep(), as this will hang the UI thread (unless you spin ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Socket Client , abnormal behavior when sending byte
    ... >>1) Are you using UDP instead of TCP? ... Ooohhh. ... sleep() is a static method that operates on whatever the current thread ...
    (comp.lang.java.programmer)