public void run() { long wait_time = 0; int my_wait = 0; int working = 0; int detached = 0; // until shut down while (true) { // sync on area synchronized (area) { // get status working = me.getStatus(); // max wait time in seconds my_wait = area.getWaitTime(); } // end-sync // When 'posted' or 'started' if ((working == QueueDetail.POSTED) || (working == QueueDetail.STARTED)) { // reset the posted indicator posted = false; // check for work to do checkWork(); // When something went wrong, (status=disabled), get out if (had_problem) { // finished return; } // endif // compute the max time to wait = seconds to milli- wait_time = my_wait * 1000; // sync on this synchronized (this) { // spin until posted while (!posted) { try { // wait for a posting or time out wait(wait_time); // When timed out if (!posted) { // set temp status as inactive detached = 1; // set is posted posted = true; } // endif } // end-try catch (InterruptedException e) { } // end-catch } // end-while // reset the posted indicator posted = false; } // end-sync // When a time out occurred if (detached == 1) { // reset detached = 0; // sync on area synchronized (area) { // When still in waiting status if (me.getStatus() == QueueDetail.WAITING) { // set status as inactive me.setDetached(); } // endif } // end-sync } // end-if } else { // When disabled if (working == QueueDetail.DISABLED) { // all done return; } // endif // wait for activation // sync on this synchronized (this) { // wait for a posting while (!posted) { try { // wait for a post wait(); } // end-try catch (InterruptedException e) { } // end-catch } // end-while // reset the posted indicator posted = false; } // end-sync } // endif } // end-while } // end-method