GeeCON Prague 2014*
The moose likes Threads and Synchronization and the fly likes Why are sleep(), yield() and interrupted() static? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Why are sleep(), yield() and interrupted() static?" Watch "Why are sleep(), yield() and interrupted() static?" New topic
Author

Why are sleep(), yield() and interrupted() static?

matt love
Ranch Hand

Joined: Jan 25, 2010
Posts: 67
It seems to me more intuitive to think of each as instance methods.

Thanks.

Matt
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Because they apply to the current thread. Certainly you wouldn't want just any thread to call sleep() or yield() on your thread. And you probably wouldn't want another thread to be able to clear your current thread's interrupted flag.

matt love
Ranch Hand

Joined: Jan 25, 2010
Posts: 67
Thanks Jeff.

Makes terrific sense.

Matt

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why are sleep(), yield() and interrupted() static?