public synchronized void scanLibrary() {
   if (scanner == null) {
     scanner = new Thread(this, "Library Scanner");
     scanner.start();
   } else if (scanner.isAlive()) {
     LOGGER.info("Scanner is already running !");
   } else {
     scanner = new Thread(this, "Library Scanner");
     scanner.start();
   }
 }
Ejemplo n.º 2
0
 public synchronized void start() {
   // When applet is started or restarted, start or
   // restart the thread.
   status = GO; // Indicates that the applet is running.
   if (runner == null || !runner.isAlive()) {
     tower = null;
     runner = new Thread(this);
     runner.start();
   } else {
     notify();
   }
 }
  public void testWaitsTillProgressBarCompletes() {
    final JFrame frame = new JFrame();

    final JProgressBar progressBar1 = new JProgressBar();
    final JProgressBar progressBar2 = new JProgressBar(0, 10);
    createProgressBarsInFrame(frame, progressBar1, progressBar2);
    setFocusManager(frame);

    windowContext.propertyChange(new PropertyChangeEvent(this, "focusOwner", null, progressBar2));

    long before = System.currentTimeMillis();

    Thread thread1 = spawnFirstThreadToInactivateFirstProgressBar(progressBar1);
    Thread thread2 = spawnSecondThreadToInactivateSecondProgressBar(progressBar2);

    windowContext.waitForProgressBar();
    long after = System.currentTimeMillis();

    assertTrue((after - before) > 500);
    ThreadUtil.sleep(100);
    assertFalse(thread1.isAlive());
    assertFalse(thread2.isAlive());
    frame.dispose();
  }
 public boolean runMacroTool(String name) {
   for (int i = 0; i < nMacros; i++) {
     if (macroNames[i].startsWith(name)) {
       if (macroToolThread != null
           && macroToolThread.getName().indexOf(name) != -1
           && macroToolThread.isAlive())
         return false; // do nothing if this tool is already running
       MacroRunner mw = new MacroRunner(pgm, macroStarts[i], name, (String) null);
       macroToolThread = mw.getThread();
       // IJ.log("runMacroTool: "+macroToolThread);
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 5
0
  @SuppressWarnings({"BusyWait"})
  private static void forceInterrupt(Thread thread) {
    /*
      ddmlib has incorrect handling of InterruptedException, so we need to invoke it several times,
      because there are three blocking invokation in succession
    */

    for (int i = 0; i < 6 && thread.isAlive(); i++) {
      thread.interrupt();
      try {
        Thread.sleep(200);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
  }
Ejemplo n.º 6
0
 public void run() {
   while (runner.isAlive()) {
     try {
       Thread.sleep(1000);
     } catch (Exception ex) {
     }
   }
   Runnable update =
       new Runnable() {
         public void run() {
           running = false;
           setStatus();
         }
       };
   SwingUtilities.invokeLater(update);
 }
  /**
   * Ensure that the message loop thread is running. This method simply returns if the thread is
   * already running. It creates a new thread if the message thread is not running. This method does
   * not return until the message loop is initialized and ready for use.
   */
  protected void ensureMessageLoopRunning() {
    synchronized (webViewUILock) {
      if (webViewUI == null || !webViewUI.isAlive()) {
        webViewMessageLoop = 0;

        // Create a new thread to run the web view message loop.
        webViewUI =
            new Thread("WebView UI") {
              public void run() {
                try {
                  // Create a message loop in native code. This call must return
                  // before any messages are sent to the WebView.
                  webViewMessageLoop = WindowsWebViewJNI.newMessageLoop();
                } catch (Throwable t) {
                  webViewMessageLoop = -1;
                } finally {
                  // Notify the outer thread that the message loop is ready or failed to start.
                  synchronized (webViewUILock) {
                    webViewUILock.notify();
                  }
                }

                // Process messages in native code until the message loop
                // is terminated.
                WindowsWebViewJNI.runMessageLoop(webViewMessageLoop);
              }
            };
        webViewUI.start();

        // Wait for the newly started thread to create the message loop. We cannot
        // safely use the WebView until the message loop has been initialized.
        while (webViewMessageLoop == 0) {
          try {
            webViewUILock.wait(1000);
          } catch (InterruptedException ignored) {
          }
        }
      }
    }
  }
Ejemplo n.º 8
0
  void killPlayThread() {
    tellThreadToStop();

    try {
      if (playThread != null) {
        while (playThread.isAlive()) {
          try {
            playThread.interrupt();
          }
          // Ignore security exceptions resulting from
          // attempting to interrupt a thread.
          // TODO Explain this better.
          catch (SecurityException ex) {
          }
          playThread.join(50);
        }

        playThread = null;
      }
    } catch (InterruptedException ex) {
      System.out.println("Interrupted while killing the play thread.  Shouldn't happen.");
    }
  }
Ejemplo n.º 9
0
 private void run() {
   int port = Util.getInt(serverPort.tf.getText().trim(), config.port);
   if (port != config.port) {
     try {
       Element server = Util.getFirstNamedChild(config.configXML, "Server");
       server.setAttribute("port", Integer.toString(port));
       config.saveXML();
       config.port = port;
     } catch (Exception unable) {
     }
     serverPort.tf.setText(Integer.toString(config.port));
   }
   save();
   if (!running) {
     runner = Util.startup();
     Util.wait(500);
     running = runner.isAlive();
     if (running) {
       monitor = new Monitor(runner);
       monitor.start();
     }
   }
   setStatus();
 }
Ejemplo n.º 10
0
 private void runCpu() {
   if (cpuThread != null && cpuThread.isAlive()) return;
   runButton.setEnabled(false);
   execButton.setEnabled(false);
   stepButton.setEnabled(false);
   pauseButton.setEnabled(true);
   cpuThread =
       new Thread(
           new Runnable() {
             public void run() {
               debugger.run();
               // on halt
               runButton.setEnabled(true);
               execButton.setEnabled(true);
               stepButton.setEnabled(true);
               pauseButton.setEnabled(false);
               registersModel.fireUpdate();
               memoryModel.fireUpdate(0, RAM_SIZE - 1); // TODO optimize
             }
           },
           "CpuThread");
   cpuThread.setDaemon(true);
   cpuThread.start();
 }
Ejemplo n.º 11
0
 public void stop() {
   if (relaxer.isAlive()) {
     relaxer.stop();
   }
   relaxer = null;
 }
Ejemplo n.º 12
0
 public boolean isAlive() {
   return thread.isAlive();
 }
Ejemplo n.º 13
0
 public synchronized void stopScanLibrary() {
   if (scanner != null && scanner.isAlive()) {
     PMS.get().getRootFolder(null).stopScan();
   }
 }
Ejemplo n.º 14
0
 public synchronized boolean isScanLibraryRunning() {
   return scanner != null && scanner.isAlive();
 }