List of usage examples for java.lang Thread interrupt
public void interrupt()
From source file:Main.java
public static void main(String[] args) { System.out.println("#1:" + Thread.interrupted()); Thread mainThread = Thread.currentThread(); mainThread.interrupt(); System.out.println("#2:" + mainThread.isInterrupted()); System.out.println("#3:" + mainThread.isInterrupted()); System.out.println("#4:" + Thread.interrupted()); System.out.println("#5:" + mainThread.isInterrupted()); }
From source file:Test.java
public static void main(String[] args) { ConcurrentMap<Integer, String> concurrentMap = new ConcurrentHashMap<Integer, String>(); for (int i = 0; i < 1000; i++) { startUpdateThread(i, concurrentMap); }//ww w .ja v a 2 s. c o m for (Map.Entry<Integer, String> entry : concurrentMap.entrySet()) { System.out.println("Key :" + entry.getKey() + " Value:" + entry.getValue()); } for (Thread thread : updateThreads) { thread.interrupt(); } }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { Thread t = new Thread(Main::run); t.start();//from ww w . ja v a 2 s. c om Thread.sleep(5000); t.interrupt(); }
From source file:PiInterrupt.java
public static void main(String[] args) { PiInterrupt pi = new PiInterrupt(); Thread t = new Thread(pi); t.start();//from w ww.j a va 2 s .co m try { Thread.sleep(10000); t.interrupt(); } catch (InterruptedException x) { } }
From source file:ThreadDemo.java
public static void main(String args[]) { Thread t = new Thread(new ThreadDemo()); System.out.println("Executing " + t.getName()); t.start();//from w w w . j a v a 2s. com if (!t.interrupted()) { t.interrupt(); } // block until other threads finish try { t.join(); } catch (InterruptedException e) { } }
From source file:ThreadDemo.java
public static void main(String args[]) { Thread t = new Thread(new ThreadDemo()); System.out.println("Executing " + t.getName()); t.start();/*from ww w.j av a 2 s . co m*/ if (!t.isInterrupted()) { t.interrupt(); } try { t.join(); } catch (InterruptedException e) { } }
From source file:MyThread.java
public static void main(String args[]) throws Exception { Thread thrd = new Thread(new MyThread(), "MyThread #1"); Thread thrd2 = new Thread(new MyThread(), "MyThread #2"); thrd.start();//from w ww.j a v a 2 s. c o m Thread.sleep(100); thrd.interrupt(); thrd2.start(); Thread.sleep(400); thrd2.interrupt(); }
From source file:MyThread.java
public static void main(String args[]) throws Exception { Thread thrd = new Thread(new MyThread(), "MyThread #1"); Thread thrd2 = new Thread(new MyThread(), "MyThread #2"); thrd.start();/*from ww w. ja v a2 s.c o m*/ Thread.sleep(1000); thrd.interrupt(); thrd2.start(); Thread.sleep(4000); thrd2.interrupt(); }
From source file:Main.java
public static void main(String[] args) { Thread t = new Thread(Main::run); t.start();//from w ww . j ava 2 s . co m try { Thread.currentThread().sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } t.interrupt(); }
From source file:SyncBlock.java
public static void main(String[] args) { try {//from w ww. ja v a2 s . com SyncBlock sb = new SyncBlock(); Thread t1 = launch(sb, "T1"); Thread.sleep(500); Thread t2 = launch(sb, "T2"); Thread t3 = launch(sb, "T3"); Thread.sleep(1000); print("about to interrupt T2"); t2.interrupt(); print("just interrupted T2"); } catch (InterruptedException x) { x.printStackTrace(); } }