Example usage for java.lang Thread stop

List of usage examples for java.lang Thread stop

Introduction

In this page you can find the example usage for java.lang Thread stop.

Prototype

@Deprecated(since = "1.2")
public final void stop() 

Source Link

Document

Forces the thread to stop executing.

Usage

From source file:Main.java

/**
 * Special method to avoid deprecation warnings calling thread.stop in Scala.
 *//*  w ww . j  a v  a2  s  .c  o  m*/
@SuppressWarnings("deprecation")
static public void stop(Thread thread) {
    thread.stop();
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static void stopThread(Thread thread) {
    thread.stop();
}

From source file:org.nuxeo.runtime.management.jvm.ThreadDeadlocksDetector.java

@SuppressWarnings("deprecation")
public static void killThreads(Set<Long> ids) {
    Map<Long, Thread> threads = getThreads();
    for (long id : ids) {
        Thread thread = threads.get(id);
        if (thread == null) {
            continue;
        }/*www.j  a  v a2  s.c o  m*/
        thread.stop();
    }
}

From source file:org.objectweb.proactive.extensions.timitspmd.TimIt.java

@SuppressWarnings("deprecation")
public static void threadsCleaning() {
    ThreadGroup tg = Thread.currentThread().getThreadGroup().getParent();
    Thread[] threads = new Thread[200];
    int len = tg.enumerate(threads, true);
    int nbKilled = 0;

    for (int i = 0; i < len; i++) {
        Thread ct = threads[i];

        if ((ct.getName().indexOf("RMI RenewClean") >= 0) || (ct.getName().indexOf("ThreadInThePool") >= 0)) {
            nbKilled++;//from w w w. j a va  2 s.  c  o m
            ct.stop();
        }
    }

    System.err.println(nbKilled + " thread(s) stopped on " + len);
}

From source file:org.b3log.symphony.util.Markdowns.java

/**
 * Converts the specified markdown text to HTML.
 *
 * @param markdownText the specified markdown text
 * @return converted HTML, returns an empty string "" if the specified markdown text is "" or {@code null}, returns
 * 'markdownErrorLabel' if exception//from   ww  w  .jav  a  2  s.co  m
 */
public static String toHTML(final String markdownText) {
    if (Strings.isEmptyOrNull(markdownText)) {
        return "";
    }

    final String cachedHTML = getHTML(markdownText);
    if (null != cachedHTML) {
        return cachedHTML;
    }

    final ExecutorService pool = Executors.newSingleThreadExecutor();
    final long[] threadId = new long[1];

    final Callable<String> call = () -> {
        threadId[0] = Thread.currentThread().getId();

        String html = LANG_PROPS_SERVICE.get("contentRenderFailedLabel");

        if (MARKED_AVAILABLE) {
            html = toHtmlByMarked(markdownText);
            if (!StringUtils.startsWith(html, "<p>")) {
                html = "<p>" + html + "</p>";
            }
        } else {
            com.vladsch.flexmark.ast.Node document = PARSER.parse(markdownText);
            html = RENDERER.render(document);
            if (!StringUtils.startsWith(html, "<p>")) {
                html = "<p>" + html + "</p>";
            }
        }

        final Document doc = Jsoup.parse(html);
        final List<org.jsoup.nodes.Node> toRemove = new ArrayList<>();
        doc.traverse(new NodeVisitor() {
            @Override
            public void head(final org.jsoup.nodes.Node node, int depth) {
                if (node instanceof org.jsoup.nodes.TextNode) {
                    final org.jsoup.nodes.TextNode textNode = (org.jsoup.nodes.TextNode) node;
                    final org.jsoup.nodes.Node parent = textNode.parent();

                    if (parent instanceof Element) {
                        final Element parentElem = (Element) parent;

                        if (!parentElem.tagName().equals("code")) {
                            String text = textNode.getWholeText();
                            boolean nextIsBr = false;
                            final org.jsoup.nodes.Node nextSibling = textNode.nextSibling();
                            if (nextSibling instanceof Element) {
                                nextIsBr = "br".equalsIgnoreCase(((Element) nextSibling).tagName());
                            }

                            if (null != userQueryService) {
                                try {
                                    final Set<String> userNames = userQueryService.getUserNames(text);
                                    for (final String userName : userNames) {
                                        text = text.replace('@' + userName + (nextIsBr ? "" : " "),
                                                "@<a href='" + Latkes.getServePath() + "/member/" + userName
                                                        + "'>" + userName + "</a> ");
                                    }
                                    text = text.replace("@participants ",
                                            "@<a href='https://hacpai.com/article/1458053458339' class='ft-red'>participants</a> ");
                                } finally {
                                    JdbcRepository.dispose();
                                }
                            }

                            if (text.contains("@<a href=")) {
                                final List<org.jsoup.nodes.Node> nodes = Parser.parseFragment(text, parentElem,
                                        "");
                                final int index = textNode.siblingIndex();

                                parentElem.insertChildren(index, nodes);
                                toRemove.add(node);
                            } else {
                                textNode.text(Pangu.spacingText(text));
                            }
                        }
                    }
                }
            }

            @Override
            public void tail(org.jsoup.nodes.Node node, int depth) {
            }
        });

        toRemove.forEach(node -> node.remove());

        doc.select("pre>code").addClass("hljs");
        doc.select("a").forEach(a -> {
            String src = a.attr("href");
            if (!StringUtils.startsWithIgnoreCase(src, Latkes.getServePath())) {
                try {
                    src = URLEncoder.encode(src, "UTF-8");
                } catch (final Exception e) {
                }
                a.attr("href", Latkes.getServePath() + "/forward?goto=" + src);
                a.attr("target", "_blank");
            }
        });
        doc.outputSettings().prettyPrint(false);

        String ret = doc.select("body").html();
        ret = StringUtils.trim(ret);

        // cache it
        putHTML(markdownText, ret);

        return ret;
    };

    Stopwatchs.start("Md to HTML");
    try {
        final Future<String> future = pool.submit(call);

        return future.get(MD_TIMEOUT, TimeUnit.MILLISECONDS);
    } catch (final TimeoutException e) {
        LOGGER.log(Level.ERROR, "Markdown timeout [md=" + markdownText + "]");
        Callstacks.printCallstack(Level.ERROR, new String[] { "org.b3log" }, null);

        final Set<Thread> threads = Thread.getAllStackTraces().keySet();
        for (final Thread thread : threads) {
            if (thread.getId() == threadId[0]) {
                thread.stop();

                break;
            }
        }
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, "Markdown failed [md=" + markdownText + "]", e);
    } finally {
        pool.shutdownNow();

        Stopwatchs.end();
    }

    return LANG_PROPS_SERVICE.get("contentRenderFailedLabel");
}

From source file:mServer.upload.MserverFtp.java

public static boolean uploadFtp(String srcPathFile_, String destFileName_, MserverDatenUpload datenUpload_) {
    try {// ww w .  j  a v a  2 s  . c  o  m
        srcPathFile = srcPathFile_;
        destFileName = destFileName_;
        datenUpload = datenUpload_;
        server = datenUpload.arr[MserverDatenUpload.UPLOAD_SERVER_NR];
        strPort = datenUpload.arr[MserverDatenUpload.UPLOAD_PORT_NR];
        username = datenUpload.arr[MserverDatenUpload.UPLOAD_USER_NR];
        password = datenUpload.arr[MserverDatenUpload.UPLOAD_PWD_NR];
        MserverLog.systemMeldung("");
        MserverLog.systemMeldung("----------------------");
        MserverLog.systemMeldung("Upload start");
        MserverLog.systemMeldung("Server: " + server);
        Thread t = new Thread(new Ftp());
        t.start();

        int warten = MserverKonstanten.MAX_WARTEN_FTP_UPLOAD /*Minuten*/;
        MserverLog.systemMeldung("Max Laufzeit FTP[Min]: " + warten);
        MserverLog.systemMeldung("-----------------------------------");
        warten = 1000 * 60 * warten;
        t.join(warten);

        if (t != null) {
            if (t.isAlive()) {
                MserverLog.fehlerMeldung(396958702, MserverFtp.class.getName(),
                        "Der letzte FtpUpload luft noch");
                MserverLog.systemMeldung("und wird gekillt");
                t.stop();
                retFtp = false;
            }
        }
    } catch (Exception ex) {
        MserverLog.fehlerMeldung(739861047, MserverFtp.class.getName(), "uploadFtp", ex);
    }
    return retFtp;
}

From source file:com.googlecode.psiprobe.controllers.threads.KillThreadController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String threadName = ServletRequestUtils.getStringParameter(request, "thread", null);

    Thread thread = null;
    if (threadName != null) {
        thread = Utils.getThreadByName(threadName);
    }/*from  w  w  w .j a  va 2s  .c  o m*/

    if (thread != null) {
        thread.stop();
    }

    String referer = request.getHeader("Referer");
    String redirectURL;
    if (referer != null) {
        redirectURL = referer.replaceAll(replacePattern, "");
    } else {
        redirectURL = request.getContextPath() + getViewName();
    }
    return new ModelAndView(new RedirectView(redirectURL));
}

From source file:net.testdriven.psiprobe.controllers.threads.KillThreadController.java

@Override
@SuppressWarnings("deprecation")
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String threadName = ServletRequestUtils.getStringParameter(request, "thread", null);

    Thread thread = null;
    if (threadName != null) {
        thread = Utils.getThreadByName(threadName);
    }//w  w  w.  jav  a 2 s .c o m

    if (thread != null) {
        thread.stop();
    }

    String referer = request.getHeader("Referer");
    String redirectURL;
    if (referer != null) {
        redirectURL = referer.replaceAll(replacePattern, "");
    } else {
        redirectURL = request.getContextPath() + getViewName();
    }
    return new ModelAndView(new RedirectView(redirectURL));
}

From source file:org.davidmendoza.fileUpload.utils.ContextFinalizer.java

@Override
public void onApplicationEvent(ContextClosedEvent e) {
    log.info("Stopping connections");
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    Driver d = null;/*ww w . j  a v  a  2  s . com*/
    while (drivers.hasMoreElements()) {
        try {
            d = drivers.nextElement();
            DriverManager.deregisterDriver(d);
            log.warn(String.format("Driver %s deregistered", d));
        } catch (SQLException ex) {
            log.warn(String.format("Error deregistering driver %s", d), ex);
        }
    }
    Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
    Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);
    for (Thread t : threadArray) {
        if (t.getName().contains("Abandoned connection cleanup thread")) {
            synchronized (t) {
                t.stop(); //don't complain, it works
            }
        }
    }
    log.info("Finished stopping connections");
}

From source file:psiprobe.controllers.threads.KillThreadController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    String threadName = ServletRequestUtils.getStringParameter(request, "thread", null);

    Thread thread = null;
    if (threadName != null) {
        thread = Utils.getThreadByName(threadName);
    }/*from   www .  ja va  2  s. c  o  m*/

    if (thread != null) {
        thread.stop();
    }

    String referer = request.getHeader("Referer");
    String redirectUrl;
    if (referer != null) {
        redirectUrl = referer.replaceAll(replacePattern, "");
    } else {
        redirectUrl = request.getContextPath() + getViewName();
    }
    return new ModelAndView(new RedirectView(redirectUrl));
}