I thought that as long as the notify() & wait() are in the same class
interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) {
while (<condition does not hold>)
obj.wait(timeout, nanos);
... // Perform action appropriate to condition
}
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
but still failed.Worker.this.notify();
Exception in thread "Thread-0" java.lang.IllegalMonitorStateException
Jeansonne Pierre wrote:Hi Matthew Brown & Chris Hurst,
i saw it now, basically I'm not calling wait() and notify() on the same objects.
wait() is in Worker object
notify() is in the SwingWorker object (anonymous object)
So I've change it tobut still failed.Worker.this.notify();
with theException in thread "Thread-0" java.lang.IllegalMonitorStateException
I have tried to print out both object's identify to validate whether they are monitoring the same object, in fact, yes. Same object
but why still failed? please help :'(
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device A-1
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device B-2
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device C-3
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device D-4
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device E-5
Waiting || com.controller.Worker@1181a0d
Notify || com.controller.Worker@fe5c8e
Device A-1
Try to write a class which controls the serial port by itself, in fact a class which encapsulates all of the processing of the serial port including opening it, reading and writing, and closing it.
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Try to write a class which controls the serial port by itself, in fact a class which encapsulates all of the processing of the serial port including opening it, reading and writing, and closing it.
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device A-1
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device B-2
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device C-3
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device D-4
Waiting || com.controller.Worker@fe5c8e
Notify || com.controller.Worker@fe5c8e
Device E-5
Waiting || com.controller.Worker@1181a0d
Notify || com.controller.Worker@fe5c8e
Device A-1
Button Clicked
Waiting || com.controller.Synchronizer@1dca662
Notifying || com.controller.Synchronizer@1dca662
Device A-1
Waiting || com.controller.Synchronizer@1dca662
Notifying || com.controller.Synchronizer@1dca662
Device B-2
Waiting || com.controller.Synchronizer@1dca662
Notifying || com.controller.Synchronizer@1dca662
Device C-3
Waiting || com.controller.Synchronizer@1dca662
Notifying || com.controller.Synchronizer@1dca662
Device D-4
Waiting || com.controller.Synchronizer@1dca662
Notifying || com.controller.Synchronizer@1dca662
Device E-5
Button Clicked
Waiting || com.controller.Synchronizer@c1cf45
Notifying || com.controller.Synchronizer@c1cf45
Device A-1
Waiting || com.controller.Synchronizer@c1cf45
Notifying || com.controller.Synchronizer@c1cf45
Device B-2
Waiting || com.controller.Synchronizer@c1cf45
Notifying || com.controller.Synchronizer@c1cf45
Device C-3
Waiting || com.controller.Synchronizer@c1cf45
Notifying || com.controller.Synchronizer@c1cf45
Device D-4
Waiting || com.controller.Synchronizer@c1cf45
Notifying || com.controller.Synchronizer@c1cf45
Device E-5
Put || com.controller.Synchronizer@6c8187
Put || com.controller.Synchronizer@6c8187
Consume || com.controller.Synchronizer@6c8187
Device A-1 Device B-2
Button Clicked
Put || com.controller.Synchronizer@6c8187
Put || com.controller.Synchronizer@6c8187
Consume || com.controller.Synchronizer@6c8187
Device A-1 Device B-2
Put || com.controller.Synchronizer@6c8187
Consume || com.controller.Synchronizer@6c8187
Device C-3
Put || com.controller.Synchronizer@6c8187
Consume || com.controller.Synchronizer@6c8187
Device D-4
Put || com.controller.Synchronizer@6c8187
Consume || com.controller.Synchronizer@6c8187
Device E-5
Button Clicked
Put || com.controller.Synchronizer@7db59f
Put || com.controller.Synchronizer@7db59f
Consume || com.controller.Synchronizer@7db59f
Device A-1 Device B-2
Put || com.controller.Synchronizer@7db59f
Consume || com.controller.Synchronizer@7db59f
Device C-3
Put || com.controller.Synchronizer@7db59f
Consume || com.controller.Synchronizer@7db59f
Device D-4
Put || com.controller.Synchronizer@7db59f
Consume || com.controller.Synchronizer@7db59f
Device E-5