java - Mass IllegalMonitorStateException on thread wait -
Whenever I call pauseThread () it always throws an illegal monitorstate exception.
I have seen in the documentation that I
with this part of the code
synchronize (obj) {while not (& lt; condition does not ););) Obj.wait (); ... // Apply appropriate action for the condition} In this case, Ozam Ultimate will be runner while (serverteckhandler .pikblockdist cue () == faucet) {} But when obj .wait (); Should have been informed? Or when this condition is not correct, is this synchronized () {} code block consistently loop or it will require loop sometime within synchronized () {}?
Edit: Does the synchronized () {} come in by running the method?
Here's my class
Public class serverTick-SavingsHolder running {Private Stable Thread Runner; / ** * When using some tools, block destruction creates a new thread to deal with logging. * @ The name of the ultimate yarn thread. * / Public serverTickSaveHandler (string thread name) {runner = new thread (this, thread name); } / ** * If the thread has nothing to do, we will stop it, so it does not run out: D. * @row blocked / exception * / public zero pauseThread (try {} tryner.wait (try); } Grip (Interrupted e) e.printStackTrace (); } Grip (Invalid monitorstate exception e) {e.printStackTrace (); }} / ** * This thread will resume if item dropItQ is needed. * @throw Invalid MonitorState applications * / Public Wide Resume Thread () {tryner.notify ()}} Grip (Invalid monitorstate exception e) {e.printStackTrace (); }} / ** * Thread which is created when this object is created * / Public run zero () {while (true) {// long start = System.currentTimeMillis (); WorldData WorldData = ServerTekerDollar.JetblockDistNinance (); If (world data! = Null) {worldData.saveToFile (); } And Pause Thread (); // long end = System.currentTimeMillis (); // Number format formattor = new passphrase ("# 0.00000"); // Utils.log ("tick tick handler execution time is" + // format. Format ((end-start) / 1000d) + "seconds"); }} / ** * Starts threads * @ throglestate expansion * / Public wired start (try {try} runner.start ()}} hold (IllegalStateException e) {e.printStackTrace (); }}}}
As a document, the object you call on < Code> wait () / notify () . Since you are calling these methods on runner , these instructions should be in a synchronize (runner) needed .
He said, calling stop () / notify () is a strange option on a thread. You can make better use of a final, dedicated lock object to wait / inform your other program. For example, starting a stationary field with a constructor. wait () and notify () are of very low level, instead you should use higher levels such as locks, Semaphores, countdown lats, blocking quays etc.
Comments
Post a Comment