List of usage examples for java.lang Thread interrupt
public void interrupt()
From source file:Main.java
/** * Interrupts/stops all threads that currently exist in threadpool *//*from w ww . ja v a2 s . c o m*/ // TODO: Craig: May want to check if they are active first? Will it cause an error // if you try and interrupt a thread that is already interrupted? public static void stopAll() { for (Thread th : threadPool.values()) { th.interrupt(); } }
From source file:Main.java
public static void interruptAndTillDies(final Thread thread) { if (thread != null) { thread.interrupt(); tillDies(thread);//w w w .ja va 2 s. c om } }
From source file:Main.java
public static void interrupt(Thread thread) { if (null != thread && !thread.isInterrupted()) { thread.interrupt(); }/*w ww.j ava 2s. co m*/ }
From source file:Main.java
/** * Interrupts the specified Thread, guarding against null. * <p/>/*from www .j av a2s .c o m*/ * @param thread the Thread to interrupt. * @see java.lang.Thread#interrupt() */ public static void interrupt(final Thread thread) { if (thread != null) { thread.interrupt(); } }
From source file:Main.java
/** * Interrupt the specified thread. Returns true if it was able to * interrupt the specified thread or false if the specified thread * is the current thread and thus interrupt was not called. *///from www .j a v a 2 s . co m public static boolean interrupt(Thread thread) { if (thread != Thread.currentThread()) { thread.interrupt(); return true; } return false; }
From source file:Main.java
public static void interrupt(Thread thread) { try {/*from w w w . j a va 2s . c o m*/ if (thread != null) { thread.interrupt(); } } catch (Exception x) { // Ignored } }
From source file:Main.java
/** * Interrupts a given thread and tries to join it. * * @param thread the thread to interrupt. * @param joinTimeoutMillis a join timeout. *//*from ww w . jav a2 s .com*/ public static void interruptAndJoin(final Thread thread, final long joinTimeoutMillis) { thread.interrupt(); try { thread.join(joinTimeoutMillis); } catch (final InterruptedException ignored) { Thread.currentThread().interrupt(); } }
From source file:Main.java
public static void safeJoin(Thread thread) throws InterruptedException { thread.join(500);//from w w w.ja v a 2 s.c o m thread.interrupt(); thread.join(); }
From source file:Main.java
/** * Convention is to use class name of the class performing the task as thread name * @param threadName/*from w w w .java2 s . c o m*/ */ public static void interrupt(String threadName) { Enumeration e = threads.elements(); while (e.hasMoreElements()) { Thread t = (Thread) e.nextElement(); if (t.getName().equals(threadName)) { t.interrupt(); } } }
From source file:Main.java
/** * Put a thread to sleep for a set number of milliseconds * @param thread the thread// w w w. j a v a 2 s . c o m * @param milliseconds the sleep time */ public static void sleep(Thread thread, int milliseconds) { try { thread.sleep(milliseconds); } catch (InterruptedException e) { thread.interrupt(); } }