コード例 #1
1
 private void shutdown() {
   writerRunner.shutdown();
   readerRunner.shutdown();
   if (writerThread.isAlive()) {
     writerThread.interrupt();
   }
   if (readerThread.isAlive()) {
     readerThread.interrupt();
   }
 }
コード例 #2
1
ファイル: Debug.java プロジェクト: umairwaheed/BitMate
  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());
    }
  }
コード例 #3
0
  @Test
  public void testAPIMPubAndReceipt() throws Exception {

    // Create a listener
    CountDownLatch listeningSignal = new CountDownLatch(1);
    CountDownLatch doneSignal = new CountDownLatch(1);
    Thread listener = new ListenerThread(listeningSignal, doneSignal);
    listener.start();
    listeningSignal.await();

    // Publish an APIM event
    try {
      Map<String, List<String>> mdMap = new HashMap<String, List<String>>();
      List<String> destinations = new ArrayList<String>();
      destinations.add("fedora.apim.update");
      mdMap.put(MessageType.apimUpdate.toString(), destinations);
      Messaging msg = new MessagingImpl(getBaseURL(), mdMap, jmsMgr);
      Object[] invocationHandlers = {new NotificationInvocationHandler(msg)};
      Management mgmt = new MockManagementDelegate();
      Management proxy = (Management) ProxyFactory.getProxy(mgmt, invocationHandlers);
      proxy.purgeObject(new MockContext(), "demo:test", null);
    } catch (Exception e) {
      listener.interrupt();
      throw e;
    }
    // await message receipt & evaluation
    doneSignal.await();
  }
コード例 #4
0
 private static <R> void verifyInvocationCannotBeInterrupted(final WSTester<R> inTester)
     throws Exception {
   resetServiceParameters();
   getMockSAService().setSleep(true);
   inTester.setReturnValue(false);
   final Semaphore sema = new Semaphore(0);
   final AtomicReference<Exception> interruptFailure = new AtomicReference<Exception>();
   Thread t =
       new Thread() {
         @Override
         public void run() {
           sema.release();
           try {
             inTester.invokeApi(false);
           } catch (Exception ex) {
             interruptFailure.set(ex);
           }
         }
       };
   t.start();
   // Wait for the thread to be started
   sema.acquire();
   // Interrupt it as soon as it is found started
   t.interrupt();
   // wait for it to end
   t.join();
   // verify that we are not able to interrupt it
   assertNull("API invocation got interrupted!", interruptFailure.get());
 }
コード例 #5
0
ファイル: UDP.java プロジェクト: NZDIS/jgroups
  /** 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();
    }
  }
コード例 #6
0
 @Override
 protected void onCancelPressed() {
   super.onUpdatePressed();
   if (installerThread != null) {
     installerThread.interrupt();
   }
 }
コード例 #7
0
ファイル: MainFrame.java プロジェクト: XaoZloHnH/hafen-client
 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();
   }
 }
コード例 #8
0
  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);
  }
コード例 #9
0
ファイル: WebServer.java プロジェクト: badaljain/cmpe281
 /** Stop listening on the server port. */
 public void shutdown() {
   if (listener != null) {
     Thread l = listener;
     listener = null;
     l.interrupt();
   }
 }
コード例 #10
0
  /** awaitUninterruptibly is uninterruptible */
  public void testAwaitUninterruptibly() {
    final Mutex sync = new Mutex();
    final ConditionObject c = sync.newCondition();
    final BooleanLatch pleaseInterrupt = new BooleanLatch();
    Thread t =
        newStartedThread(
            new CheckedRunnable() {
              public void realRun() {
                sync.acquire();
                assertTrue(pleaseInterrupt.releaseShared(0));
                c.awaitUninterruptibly();
                assertTrue(Thread.interrupted());
                assertHasWaitersLocked(sync, c, NO_THREADS);
                sync.release();
              }
            });

    pleaseInterrupt.acquireShared(0);
    sync.acquire();
    assertHasWaitersLocked(sync, c, t);
    sync.release();
    t.interrupt();
    assertHasWaitersUnlocked(sync, c, t);
    assertThreadStaysAlive(t);
    sync.acquire();
    assertHasWaitersLocked(sync, c, t);
    assertHasExclusiveQueuedThreads(sync, NO_THREADS);
    c.signal();
    assertHasWaitersLocked(sync, c, NO_THREADS);
    assertHasExclusiveQueuedThreads(sync, t);
    sync.release();
    awaitTermination(t);
  }
コード例 #11
0
ファイル: InterpreterFrame.java プロジェクト: DavePearce/jkit
 public void stopEvaluate() {
   // user requested run be stopped so tell
   // run thread to stop
   Thread tmp = runThread;
   runThread = null;
   tmp.interrupt();
 }
コード例 #12
0
 /** getSharedQueuedThreads returns all shared waiting threads */
 public void testGetSharedQueuedThreads_Shared() {
   final BooleanLatch l = new BooleanLatch();
   assertHasSharedQueuedThreads(l, NO_THREADS);
   Thread t1 =
       newStartedThread(
           new CheckedInterruptedRunnable() {
             public void realRun() throws InterruptedException {
               l.acquireSharedInterruptibly(0);
             }
           });
   waitForQueuedThread(l, t1);
   assertHasSharedQueuedThreads(l, t1);
   Thread t2 =
       newStartedThread(
           new CheckedRunnable() {
             public void realRun() throws InterruptedException {
               l.acquireSharedInterruptibly(0);
             }
           });
   waitForQueuedThread(l, t2);
   assertHasSharedQueuedThreads(l, t1, t2);
   t1.interrupt();
   awaitTermination(t1);
   assertHasSharedQueuedThreads(l, t2);
   assertTrue(l.releaseShared(0));
   awaitTermination(t2);
   assertHasSharedQueuedThreads(l, NO_THREADS);
 }
コード例 #13
0
 private void timeoutIfStillRunning(Thread t) {
   if (t.isAlive()) {
     log.warn("Scenario timed out after " + scenarioTimeoutMillis + " millis, will interrupt");
     stepProcessor.setInterruptingOnTimeout(true);
     t.interrupt(); // first try to interrupt to see if this can unblock/fail the scenario
   }
 }
コード例 #14
0
  /** {@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);
        }
      }
    }
  }
コード例 #15
0
 public synchronized void stop() {
   running = false;
   try {
     thread.join();
   } catch (InterruptedException e) {
     thread.interrupt();
   }
 }
コード例 #16
0
ファイル: MetaSearchRequest.java プロジェクト: chmaruni/TOP
 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();
 }
コード例 #17
0
ファイル: AppletPanel.java プロジェクト: FauxFaux/jdk9-jdk
 /** 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();
   }
 }
コード例 #18
0
ファイル: Animation.java プロジェクト: maeyler/Automata
 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();
 }
コード例 #19
0
 @Override
 public void interrupt() {
   try {
     jmsMgr.close();
   } catch (MessagingException e) {
     fail(e.getMessage());
   } finally {
     super.interrupt();
   }
 }
コード例 #20
0
  @Override
  public void testEnded(String host) {
    workerThread.interrupt();
    shutdownConnectors();

    // reset autoFileName for next test run
    autoFileBaseName = null;
    counter = 0;

    super.testEnded(host);
  }
コード例 #21
0
ファイル: Executing.java プロジェクト: rhusar/JGroups
 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");
 }
コード例 #22
0
ファイル: UDP.java プロジェクト: NZDIS/jgroups
 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;
 }
コード例 #23
0
ファイル: EvictionTest.java プロジェクト: qhfu/hazelcast
  @Test
  public void testMapRecordIdleEvictionOnMigration() throws InterruptedException {
    Config cfg = new Config();
    final String name = "testMapRecordIdleEvictionOnMigration";
    MapConfig mc = cfg.getMapConfig(name);
    int maxIdleSeconds = 10;
    int size = 100;
    final int nsize = size / 5;
    mc.setMaxIdleSeconds(maxIdleSeconds);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);

    HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
    final IMap map = instance1.getMap(name);
    final CountDownLatch latch = new CountDownLatch(size - nsize);
    map.addEntryListener(
        new EntryAdapter() {
          public void entryEvicted(EntryEvent event) {
            latch.countDown();
          }
        },
        false);

    for (int i = 0; i < size; i++) {
      map.put(i, i);
    }
    final Thread thread =
        new Thread(
            new Runnable() {
              public void run() {
                while (!Thread.currentThread().isInterrupted()) {
                  try {
                    for (int i = 0; i < nsize; i++) {
                      map.get(i);
                    }
                    Thread.sleep(1000);
                  } catch (HazelcastInstanceNotActiveException e) {
                    return;
                  } catch (InterruptedException e) {
                    return;
                  }
                }
              }
            });
    thread.start();
    HazelcastInstance instance2 = factory.newHazelcastInstance(cfg);
    HazelcastInstance instance3 = factory.newHazelcastInstance(cfg);

    assertTrue(latch.await(1, TimeUnit.MINUTES));
    Assert.assertEquals(nsize, map.size());

    thread.interrupt();
    thread.join(5000);
  }
コード例 #24
0
 /** 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;
 }
コード例 #25
0
 @Override
 public synchronized void close() {
   logger.info("closing Remote River on this node");
   closed = true;
   if (coordinatorThread != null) {
     coordinatorThread.interrupt();
   }
   // free instances created in #start()
   coordinatorThread = null;
   coordinatorInstance = null;
   synchronized (riverInstances) {
     riverInstances.remove(riverName().getName());
   }
 }
コード例 #26
0
  @Override
  public void stop() {
    isStopped = true;

    if (schedulingThread != null) {
      synchronized (schedulingThread) {
        schedulingThread.interrupt();
      }
    }
    candidateWorkers.clear();
    scheduledRequests.clear();
    LOG.info("Task Scheduler stopped");
    super.stop();
  }
コード例 #27
0
  /** tryAcquireNanos is interruptible */
  public void testTryAcquireNanos_Interruptible() {
    final Mutex sync = new Mutex();
    sync.acquire();
    Thread t =
        newStartedThread(
            new CheckedInterruptedRunnable() {
              public void realRun() throws InterruptedException {
                sync.tryAcquireNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
              }
            });

    waitForQueuedThread(sync, t);
    t.interrupt();
    awaitTermination(t);
  }
コード例 #28
0
 /** @see java.lang.Runnable#run() */
 public void run() {
   final Thread thread = Thread.currentThread();
   while (!Thread.interrupted()) {
     m_set.add(m_touchable);
     m_list.add(m_touchable);
     try {
       synchronized (thread) {
         thread.wait();
       }
     } catch (InterruptedException e) {
       // propagate interrupt
       thread.interrupt();
     }
   }
 }
コード例 #29
0
 /** 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();
 }
コード例 #30
0
ファイル: Q2.java プロジェクト: rlishtaba/jPOS
 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;
 }