-2

When to invoke super.wait(), something like below -

synchronized (this)
      {
        while (true)
        {
          try
          {
            super.wait();
          }
          catch (InterruptedException e)
          {
            return;
          }

        }
 }
Alexis C.
  • 91,686
  • 21
  • 171
  • 177
  • 2
    Before we answer you need to say atleast, What are you trying to achieve? – Ravi Dhoriya ツ May 08 '14 at 12:44
  • well, that's a weird construct and most likely a bug. but it's still valid. why all the down votes? – Yuri May 08 '14 at 13:16
  • Well, I saw this in one of the answers by @bdonlan in this post [link](http://stackoverflow.com/questions/6114320/java-monitors-how-to-know-if-waitlong-timeout-ended-by-timeout-or-by-notify). And this is the first time I saw wait being invoked on super. So asked this question out of curiosity. – user3172924 May 08 '14 at 13:45

2 Answers2

2

Object.wait() is declared final and cannot be overridden. So super.wait() always means just wait() but is a bit longer.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Yuri
  • 1,695
  • 1
  • 13
  • 23
1

wait() must be called on the same object on which it it synchronized otherwise it will result in java.lang.IllegalMonitorStateException

It should be this.wait()

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Braj
  • 46,415
  • 5
  • 60
  • 76
  • "this" and "super" both always refer to the same object. The difference between this.foo() and super.foo() only matters when the a foo() method is defined in both the object's class and in the class of one of the class's ancestors. Then "super" allows a call to the ancestor's version of the function. The normal use case is when you define this.foo() as a wrapper around the inherited function. – Solomon Slow May 08 '14 at 18:19