Example #1
1
  public static void killAWTThreads(ThreadGroup threadGroup) {
    Thread[] threadList = new Thread[threadGroup.activeCount()];

    threadGroup.enumerate(threadList);

    for (int i = 0; i < threadList.length; i++) {

      Thread t = threadList[i];

      if (t != null) {

        String name = t.getName();

        if (name.startsWith("AWT")) {

          out("Interrupting thread '".concat(t.toString()).concat("'"));

          t.interrupt();
        }
      }
    }

    if (threadGroup.getParent() != null) {

      killAWTThreads(threadGroup.getParent());
    }
  }
  public static void main(String[] args) throws Exception {
    int counter = 0;
    while (true) {
      Thread outThread = null;
      Thread errThread = null;
      try {
        // org.pitest.mutationtest.instrument.MutationTestUnit#runTestInSeperateProcessForMutationRange

        // *** start slave

        ServerSocket commSocket = new ServerSocket(0);
        int commPort = commSocket.getLocalPort();
        System.out.println("commPort = " + commPort);

        // org.pitest.mutationtest.execute.MutationTestProcess#start
        //   - org.pitest.util.CommunicationThread#start
        FutureTask<Integer> commFuture = createFuture(commSocket);
        //   - org.pitest.util.WrappingProcess#start
        //       - org.pitest.util.JavaProcess#launch
        Process slaveProcess = startSlaveProcess(commPort);
        outThread = new Thread(new ReadFromInputStream(slaveProcess.getInputStream()), "stdout");
        errThread = new Thread(new ReadFromInputStream(slaveProcess.getErrorStream()), "stderr");
        outThread.start();
        errThread.start();

        // *** wait for slave to die

        // org.pitest.mutationtest.execute.MutationTestProcess#waitToDie
        //    - org.pitest.util.CommunicationThread#waitToFinish
        System.out.println("waitToFinish");
        Integer controlReturned = commFuture.get();
        System.out.println("controlReturned = " + controlReturned);
        // NOTE: the following won't get called if commFuture.get() fails!
        //    - org.pitest.util.JavaProcess#destroy
        outThread.interrupt(); // org.pitest.util.AbstractMonitor#requestStop
        errThread.interrupt(); // org.pitest.util.AbstractMonitor#requestStop
        slaveProcess.destroy();
      } catch (Exception e) {
        e.printStackTrace(System.out);
      }

      // test: the threads should exit eventually
      outThread.join();
      errThread.join();
      counter++;
      System.out.println("try " + counter + ": stdout and stderr threads exited normally");
    }
  }
Example #3
0
  /** Stops unicast and multicast receiver threads */
  void stopThreads() {
    Thread tmp;

    // 1. Stop the multicast receiver thread
    if (mcast_receiver != null) {
      if (mcast_receiver.isAlive()) {
        tmp = mcast_receiver;
        mcast_receiver = null;
        closeMulticastSocket(); // will cause the multicast thread to terminate
        tmp.interrupt();
        try {
          tmp.join(100);
        } catch (Exception e) {
        }
        tmp = null;
      }
      mcast_receiver = null;
    }

    // 2. Stop the unicast receiver thread
    if (ucast_receiver != null) {
      ucast_receiver.stop();
      ucast_receiver = null;
    }

    // 3. Stop the in_packet_handler thread
    if (incoming_packet_handler != null) {
      incoming_packet_handler.stop();
    }
  }
Example #4
0
 /** Stop the dispatcher so we can be destroyed. */
 void stop() {
   if (debug) System.err.println("EventQueue stopping");
   if (qThread != null) {
     qThread.interrupt(); // kill our thread
     qThread = null;
   }
 }
  public void onDestroy() {
    running = false;
    if (scanThread != null) scanThread.interrupt();

    if (myWLocate != null) myWLocate.doPause();

    sensorManager.unregisterListener(
        this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));

    if (scanData.getmView() != null) {
      ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(scanData.getmView());
      scanData.setmView(null);
    }
    try {
      if (wl != null) wl.release();
    } catch (RuntimeException re) {
    }
    wl = null;
    try {
      scanThread.join(1000);
    } catch (InterruptedException ie) {

    }
    System.exit(0);
  }
Example #6
0
 /** Stop listening on the server port. */
 public void shutdown() {
   if (listener != null) {
     Thread l = listener;
     listener = null;
     l.interrupt();
   }
 }
Example #7
0
 public void run() {
   if (Thread.currentThread() != this.mt)
     throw (new RuntimeException("MainFrame is being run from an invalid context"));
   Thread ui = new HackThread(p, "Haven UI thread");
   ui.start();
   try {
     try {
       Session sess = null;
       while (true) {
         UI.Runner fun;
         if (sess == null) {
           Bootstrap bill = new Bootstrap(Config.defserv, Config.mainport);
           if ((Config.authuser != null) && (Config.authck != null)) {
             bill.setinitcookie(Config.authuser, Config.authck);
             Config.authck = null;
           }
           fun = bill;
           setTitle(String.format("Amish Paradise %s", version));
         } else {
           fun = new RemoteUI(sess);
           setTitle(String.format("Amish Paradise %s \u2013 %s", version, sess.username));
         }
         sess = fun.run(p.newui(sess));
       }
     } catch (InterruptedException e) {
     }
     savewndstate();
   } finally {
     ui.interrupt();
     dispose();
   }
 }
Example #8
0
 public void stopEvaluate() {
   // user requested run be stopped so tell
   // run thread to stop
   Thread tmp = runThread;
   runThread = null;
   tmp.interrupt();
 }
  /** {@inheritDoc} */
  public void updateBlock(Block oldblock, Block newblock) throws IOException {
    if (oldblock.getBlockId() != newblock.getBlockId()) {
      throw new IOException(
          "Cannot update oldblock (=" + oldblock + ") to newblock (=" + newblock + ").");
    }

    for (; ; ) {
      final List<Thread> threads = tryUpdateBlock(oldblock, newblock);
      if (threads == null) {
        return;
      }

      // interrupt and wait for all ongoing create threads
      for (Thread t : threads) {
        t.interrupt();
      }
      for (Thread t : threads) {
        try {
          t.join();
        } catch (InterruptedException e) {
          DataNode.LOG.warn("interruptOngoingCreates: t=" + t, e);
        }
      }
    }
  }
Example #10
0
 public synchronized void countDownInterrupt() {
   // In MetaSearchImpl.topTask_search() we schedule multiple MetaSearchResult.topTask_run()
   // tasks which then call countDownInterrupt
   // because we synchronize we don't check here even though that's a little more dangerous that I
   // would like it to be...
   // perm.checkWrite(this);
   if (thread_ != null && --counter_ == 0) thread_.interrupt();
 }
 public void changeSettingsAutoupdate(boolean autoupdate) {
   settings.setAutoupdate(autoupdate);
   if (!autoupdate) {
     updateAllInBackground.interrupt();
   } else {
     startBackgroundThread();
   }
 }
Example #12
0
  public void start(ContentHandler sax, Target target) throws IOException, SAXException {
    this.target = target;

    XMLReader parser;
    try {
      parser = spf.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException e) {
      throw new LagoonException(e.getMessage());
    }

    parser.setContentHandler(sax);
    parser.setEntityResolver(
        new EntityResolver() {
          public InputSource resolveEntity(String publicId, String systemId)
              throws SAXException, IOException {
            InputSource is = new InputSource(getSourceMan().getFileURL(systemId));

            File fil = getSourceMan().getFile(systemId);

            if (fil != null) {
              InputStream istr = new FileInputStream(fil);
              is.setByteStream(istr);
            }

            return is;
          }
        });

    exception = null;

    mis = new MyInputStream();
    mos = new MyOutputStream(mis);

    thread = new Thread(this);
    thread.start();

    parser.parse(new InputSource(mis));
    mis.close();

    try {
      thread.join(1000);
    } catch (InterruptedException e) {
    }

    if (thread.isAlive()) {
      thread.interrupt();
    }

    this.target = null;

    if (exception != null) {
      if (exception instanceof SAXException) {
        throw (SAXException) exception;
      } else if (exception instanceof IOException) {
        throw (IOException) exception;
      }
    }
  }
Example #13
0
  private synchronized String getLinuxDMIInfo(String dmiType, String target) {
    // only try to get dmidecode information once, after that, we can
    // reuse the output
    if (dmiInfo == null) {
      Thread dmidecodeThread =
          new Thread() {
            public void run() {
              dmiInfo = getCommandOutput("/usr/sbin/dmidecode");
            }
          };
      dmidecodeThread.start();

      try {
        dmidecodeThread.join(2000);
        if (dmidecodeThread.isAlive()) {
          dmidecodeThread.interrupt();
          dmiInfo = "";
        }
      } catch (InterruptedException ie) {
        dmidecodeThread.interrupt();
      }
    }

    if (dmiInfo.length() == 0) {
      return "";
    }
    boolean dmiFlag = false;
    for (String s : dmiInfo.split("\n")) {
      String line = s.toLowerCase();
      if (dmiFlag) {
        if (line.contains(target)) {
          String key = target + ":";
          int indx = line.indexOf(key) + key.length();
          if (line.contains(key) && indx < line.length()) {
            return line.substring(indx).trim();
          }
          String[] ss = line.split(":");
          return ss[ss.length - 1];
        }
      } else if (line.contains(dmiType)) {
        dmiFlag = true;
      }
    }
    return "";
  }
Example #14
0
 void setMessage(Animator a) {
   anim = a;
   who.setText(a.author());
   ref.setText(a.description());
   pan.remove(last);
   last = a.container();
   pan.add(last, "Center");
   if (T != null) T.interrupt();
 }
 @Override
 public void close() {
   if (closed) {
     return;
   }
   logger.info("closing rabbitmq river");
   closed = true;
   thread.interrupt();
 }
Example #16
0
 /** Request that the loading of the applet be stopped. */
 protected synchronized void stopLoading() {
   // REMIND: fill in the body
   if (loaderThread != null) {
     // System.out.println("Interrupting applet loader thread: " + loaderThread);
     loaderThread.interrupt();
   } else {
     setLoadAbortRequest();
   }
 }
Example #17
0
  public void stop() {
    Util.close(srv_sock);

    if (acceptor != null && acceptor.isAlive()) acceptor.interrupt();

    Util.sleep(500);
    if (!sockets.isEmpty()) {
      for (Socket sock : sockets) Util.close(sock);
    }
  }
Example #18
0
 /** 结束音乐线程 */
 public void stop() {
   if (m_midi == null) {
     musicThread.interrupt();
     musicThread = null;
     m_stopped = true;
   } else {
     m_midi.stop();
     m_midi.close();
   }
 }
Example #19
0
 public void stop() {
   Thread tmp;
   if (thread != null && thread.isAlive()) {
     running = false;
     tmp = thread;
     thread = null;
     closeSocket(); // this will cause the thread to break out of its loop
     tmp.interrupt();
     tmp = null;
   }
   thread = null;
 }
Example #20
0
 protected void handleInterruptRequest(Address source, long requestId) {
   Owner owner = new Owner(source, requestId);
   Runnable runnable = removeKeyForValue(_running, owner);
   Thread thread = null;
   if (runnable != null) {
     thread = _runnableThreads.remove(runnable);
   }
   if (thread != null) {
     thread.interrupt();
   } else if (log.isTraceEnabled())
     log.trace("Message could not be interrupted due to it already returned");
 }
 /** Disconnects from running debugged process. */
 public void disconnect() throws DebuggerException {
   threadGroup.setRemoteThreadGroup(null);
   if (remoteDebugger != null) {
     remoteDebugger.close();
     remoteDebugger = null;
   }
   if (debuggerThread != null) {
     debuggerThread.interrupt();
     debuggerThread.stop();
   }
   super.finishDebugger();
   synchronizer = null;
 }
 /** Disconnects from running debugged process. */
 public void disconnect() throws DebuggerException {
   if (breakpointMain != null) {
     for (int x = 0; x < breakpointMain.length; x++) breakpointMain[x].remove();
     breakpointMain = null;
   }
   try {
     if (virtualMachine != null) virtualMachine.dispose();
   } catch (VMDisconnectedException e) {
   }
   if (threadManager != null) threadManager.finish();
   if (debuggerThread != null) {
     debuggerThread.interrupt();
     debuggerThread.stop();
   }
   super.finishDebugger();
 }
Example #23
0
 public void shutdown(boolean join) {
   shutdown = true;
   if (q2Thread != null) {
     log.info("shutting down");
     q2Thread.interrupt();
     if (join) {
       try {
         q2Thread.join();
         log.info("shutdown done");
       } catch (InterruptedException e) {
         log.warn(e);
       }
     }
   }
   q2Thread = null;
 }
 /**
  * The disconnect method will stop the eventreplayer, and send null to the other peers, to stop
  * their reading from their streams. The GUI-menu is updated appropriately.
  */
 public void disconnect() {
   setTitle("Disconnected");
   active = false;
   if (connected == true) {
     er.stopStreamToQueue();
     ert.interrupt();
     setDocumentFilter(null);
     connected = false;
     setLocked(false);
   }
   deregisterOnPort();
   Disconnect.setEnabled(false);
   Connect.setEnabled(true);
   Listen.setEnabled(true);
   Save.setEnabled(true);
   SaveAs.setEnabled(true);
 }
  public void handleBlock(Thread thread) {

    try {
      if (socket != null) {
        logger.debug("close socket()");
        socket.close();
      }
    } catch (Exception e) {
      // ignored
    }
    synchronized (this) {
      if (thread != null) {
        logger.debug("interrupt thread()");
        thread.interrupt();
      }
    }
  }
Example #26
0
 public void close() throws Exception {
   if (isClosed) {
     System.out.println("SSH source already closed!");
     return;
   }
   System.out.println("Closing SSH log source..");
   isClosed = true;
   ftpReadThread.interrupt();
   if (reader != null)
     try {
       reader.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   if (client != null && client.isConnected()) {
     System.out.println("try to disconnect SSH channel");
     client.disconnect(true);
     System.out.println("FTP  disconnected");
   }
   buffer.clear();
 }
Example #27
0
  /**
   * Determines whether {@link #runInConnectThread(DTLSProtocol, TlsPeer, DatagramTransport)} is to
   * try to establish a DTLS connection.
   *
   * @param i the number of tries remaining after the current one
   * @param datagramTransport
   * @return <tt>true</tt> to try to establish a DTLS connection; otherwise, <tt>false</tt>
   */
  private boolean enterRunInConnectThreadLoop(int i, DatagramTransport datagramTransport) {
    if (i < 0 || i > CONNECT_TRIES) {
      return false;
    } else {
      Thread currentThread = Thread.currentThread();

      synchronized (this) {
        if (i > 0 && i < CONNECT_TRIES - 1) {
          boolean interrupted = false;

          try {
            wait(CONNECT_RETRY_INTERVAL);
          } catch (InterruptedException ie) {
            interrupted = true;
          }
          if (interrupted) currentThread.interrupt();
        }

        return currentThread.equals(this.connectThread)
            && datagramTransport.equals(this.datagramTransport);
      }
    }
  }
 public void halt() {
   scheduler.interrupt();
   listenThread.interrupt();
   Client.killAllClient();
   timer.pause();
 }
Example #29
0
  /** Method to process the build queue, can be called by more than one thread */
  public void processBuildQueue() throws TablesawException {
    BuildAction ba;
    Rule rule;
    String target;

    synchronized (m_threadList) {
      m_threadList.add(Thread.currentThread());
    }

    try {
      doloop:
      do {
        synchronized (this) {
          try {
            ba = (BuildAction) m_buildQueue.removeLast();
          } catch (NoSuchElementException nsee) {
            break doloop;
            // ba = new BuildAction(m_fileManager, null);
          }

          if (m_printDebug) Debug.print("Processing: " + ba);

          if (m_makeException != null) break doloop;

          ba.waitForDependencies();

          if (m_makeException != null) break doloop;
        }

        rule = ba.getTargetRule();
        MakeAction action = rule.getMakeAction();

        // target = ba.getTarget();
        if (action != null) {
          action.doMakeAction(rule);

          rule.verify();
        }

        Debug.print("COMPLETE - " + ba);
        ba.complete(); // Complete the BuildAction
      } while (m_makeException == null);
    } catch (Exception e) {
      TablesawException cpe;

      if (e instanceof TablesawException) cpe = (TablesawException) e;
      else cpe = new TablesawException(e);

      synchronized (this) {
        m_makeException = cpe;

        for (Thread t : m_threadList) t.interrupt();
      }

      throw cpe;
    }

    // This causes worker threads to die off and the exception to
    // pass to the main thread
    if (m_makeException != null) throw m_makeException;
  }
Example #30
0
 public void stop() {
   if (running.compareAndSet(true, false)) {
     runner.interrupt();
   }
 }