Autocompletion with Thread objects

I have been wondering for a while why autocompletion doesn't seem to work properly with Thread objects: It doesn't list the sleep and yield methods (and eventually a few others ?).

Yet if you write the sleep call yourself without enclosing it in a InterruptedException try-catch block, the parser will detect the error and the whole statement will as expected be underlined in red.

Has anyone an explanation about that paranormal phenomenon ?

5 comments
Comment actions Permalink

Most likely, this paranormal phenomenon called a bug. Please submit a
request to the tracker.

--

Eugene Belyaev, CTO
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"


"Sylvain" <sdeaux_pub@yahoo.fr> wrote in message
news:27719026.1053381214381.JavaMail.jrun@is.intellij.net...

I have been wondering for a while why autocompletion doesn't seem to work

properly with Thread objects: It doesn't list the sleep and yield methods
(and eventually a few others ?).
>

Yet if you write the sleep call yourself without enclosing it in a

InterruptedException try-catch block, the parser will detect the error and
the whole statement will as expected be underlined in red.
>

Has anyone an explanation about that paranormal phenomenon ?

>
>


0
Comment actions Permalink

It's because those methods are static, and IntelliJ defaults to ignoring static methods from an instance context. You can change the behavior under IDE Options - Completion - Show static members after instance qualifier.

0
Comment actions Permalink

Oh, i had never noticed that sleep and yield were static methods, i had taken the habit of invoking them on the Thread.currentThread() object.

Allright, thanks, this answers my question.

0
Comment actions Permalink

Yes, I believe that when you call Thread.sleep(), it puts the current thread to sleep anyways, so Thread.currentThread().sleep is the same thing as Thread.sleep(). At least that's how it was explained to me once.

0
Comment actions Permalink

Tobin Juday wrote:

Yes, I believe that when you call Thread.sleep(), it puts the current thread to sleep anyways, so Thread.currentThread().sleep is the same thing as Thread.sleep(). At least that's how it was explained to me once.


Thread.currentThread().sleep() would imply that you could cause any
thread to sleep if you have a reference to its Thread object. Since that
is not the case, sleep is a static method which always acts on the
current thread. Ditto for yield.

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://java.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: 416-643-4846 | Fax: 416-594-1919

0

Please sign in to leave a comment.