@Override public final boolean cancel( boolean mayInterruptIfRunning ) { boolean did = false; synchronized(this) { // Install the answer under lock if( !isCancelled() ) { did = true; // Did cancel (was not cancelled already) _target.taskRemove(_tasknum); _target = null; // Flag as canceled UDPTimeOutThread.PENDING.remove(this); } notifyAll(); // notify in any case } return did; }
@Override public V get() { // check priorities - FJ task can only block on a task with higher priority! Thread cThr = Thread.currentThread(); int priority = (cThr instanceof FJWThr) ? ((FJWThr)cThr)._priority : -1; // was hitting this (priority=1 but _dt.priority()=0 for DRemoteTask) - not clear who increased priority of FJWThr to 1... // assert _dt.priority() > priority || (_dt.priority() == priority && (_dt instanceof DRemoteTask || _dt instanceof MRTask2)) assert _dt.priority() > priority || ((_dt instanceof DRemoteTask || _dt instanceof MRTask2)) : "*** Attempting to block on task (" + _dt.getClass() + ") with equal or lower priority. Can lead to deadlock! " + _dt.priority() + " <= " + priority; if( _done ) return result(); // Fast-path shortcut // Use FJP ManagedBlock for this blocking-wait - so the FJP can spawn // another thread if needed. try { try { ForkJoinPool.managedBlock(this); } catch (InterruptedException e) { } } catch(Throwable t){ // catch and rethrow to preserve the stack trace! throw new RuntimeException(t); } if( _done ) return result(); // Fast-path shortcut assert isCancelled(); return null; } // Return true if blocking is unnecessary, which is true if the Task isDone.