@RandomlyFails // NB-Core-Build #8241
  public void testTheStarvation37045() throws Exception {
    org.openide.util.Task task;

    synchronized (this) {
      org.openide.util.RequestProcessor.getDefault().post(support);
      // wait for the support (another thread) to try to open and block
      wait();

      // now post there another task
      task = org.openide.util.RequestProcessor.getDefault().post(support);
      // wait for it to block, any amount of time is likely to do it
      Thread.sleep(500);

      // notify the first edit(), to continue (and throw exception)
      notify();
    }

    // check for deadlock
    for (int i = 0; i < 5; i++) {
      if (task.isFinished()) break;
      Thread.sleep(500);
    }

    // uncomment the next line if you want to see real starvation threaddump
    // task.waitFinished ();
    assertTrue("Should be finished, but there is a starvation", task.isFinished());
  }
Пример #2
0
 @Override
 public Task prepareDocument() {
   Task task = super.prepareDocument();
   // Avoid listening to the same task more than once.
   if (task != prepareTask2) {
     prepareTask2 = task;
     task.addTaskListener(
         new TaskListener() {
           public void taskFinished(Task task) {
             QuietUndoManager undo = getUndoManager();
             StyledDocument doc = getDocument();
             synchronized (undo) {
               // Now that the document is ready, pass it to the manager.
               undo.setDocument((AbstractDocument) doc);
               if (!undo.isCompound()) {
                 // The superclass prepareDocument() adds the undo/redo
                 // manager as a listener -- we need to remove it since
                 // we will initially listen to the model instead.
                 doc.removeUndoableEditListener(undo);
                 // If not listening to document, then listen to model.
                 addUndoManagerToModel(undo);
               }
             }
             prepareTask2 = null;
           }
         });
   }
   return task;
 }
Пример #3
0
 @Override
 public Task reloadDocument() {
   Task task = super.reloadDocument();
   task.addTaskListener(
       new TaskListener() {
         public void taskFinished(Task task) {
           EventQueue.invokeLater(
               new Runnable() {
                 public void run() {
                   QuietUndoManager undo = getUndoManager();
                   StyledDocument doc = getDocument();
                   // The superclass reloadDocument() adds the undo
                   // manager as an undoable edit listener.
                   synchronized (undo) {
                     if (!undo.isCompound()) {
                       doc.removeUndoableEditListener(undo);
                     }
                   }
                 }
               });
         }
       });
   return task;
 }