List of usage examples for java.lang Thread getName
public final String getName()
From source file:Main.java
public ThreadGroupDemo() { ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup"); ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup"); Thread t1 = new Thread(pGroup, this); System.out.println("Starting " + t1.getName()); t1.start();/* www . j av a 2s . c om*/ Thread t2 = new Thread(cGroup, this); System.out.println("Starting " + t2.getName()); t2.start(); Thread[] list = new Thread[pGroup.activeCount()]; int count = pGroup.enumerate(list); for (int i = 0; i < count; i++) { System.out.println("Thread " + list[i].getName() + " found"); } }
From source file:Main.java
public ThreadGroupDemo() { try {// www .jav a2 s . c o m ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup"); ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup"); Thread t1 = new Thread(pGroup, this); System.out.println("Starting " + t1.getName()); t1.start(); Thread t2 = new Thread(cGroup, this); System.out.println("Starting " + t2.getName()); t2.start(); pGroup.checkAccess(); System.out.println(pGroup.getName() + " has access"); cGroup.checkAccess(); System.out.println(cGroup.getName() + " has access"); } catch (Exception ex) { System.out.println(ex.toString()); } }
From source file:Main.java
public void run() { try {/*from w w w .j a va 2s . c o m*/ System.out.print(Thread.currentThread().getName()); System.out.println(" executing..."); while (true) { Thread.sleep(500); } } catch (InterruptedException e) { Thread currThread = Thread.currentThread(); System.out.print(currThread.getName()); System.out.println(" interrupted:" + e.toString()); // rethrow the exception throw new RuntimeException(e.getMessage()); } }
From source file:Main.java
public ThreadGroupDemo() { try {// ww w .j a v a 2s .c o m ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup"); ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup"); Thread t1 = new Thread(pGroup, this); System.out.println("Starting " + t1.getName()); t1.start(); Thread t2 = new Thread(cGroup, this); System.out.println("Starting " + t2.getName()); t2.start(); // block until the other threads finish t1.join(); t2.join(); // child group destroyed cGroup.destroy(); System.out.println(cGroup.getName() + " destroyed"); // parent group destroyed pGroup.destroy(); System.out.println(pGroup.getName() + " destroyed"); } catch (InterruptedException ex) { System.out.println(ex.toString()); } }
From source file:Main.java
public ThreadGroupDemo() { try {//from www . ja v a 2s . c om ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup"); ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup"); Thread t1 = new Thread(pGroup, this); System.out.println("Starting " + t1.getName()); t1.start(); Thread t2 = new Thread(cGroup, this); System.out.println("Starting " + t2.getName()); t2.start(); t1.join(); t2.join(); if (!cGroup.isDestroyed()) { cGroup.destroy(); } else { System.out.println(cGroup.getName() + " destroyed"); } // parent group destroyed if (!pGroup.isDestroyed()) { pGroup.destroy(); } else { System.out.println(pGroup.getName() + " destroyed"); } } catch (Exception ex) { System.out.println(ex.toString()); } }
From source file:Main.java
public ThreadGroupDemo() { MyThreadGroup pGroup = new MyThreadGroup("ParentThreadGroup"); MyThreadGroup cGroup = new MyThreadGroup(pGroup, "ChildThreadGroup"); Thread thr2 = new Thread(pGroup, this); System.out.println("Starting " + thr2.getName()); thr2.start();/*from w w w .ja v a2s .c om*/ // create third thread Thread thr3 = new Thread(cGroup, this); System.out.println("Starting " + thr3.getName()); thr3.start(); try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } thr2.interrupt(); thr3.interrupt(); }
From source file:Main.java
public ThreadGroupDemo() { ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup"); pGroup.setMaxPriority(Thread.MAX_PRIORITY - 2); ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup"); cGroup.setMaxPriority(Thread.NORM_PRIORITY); Thread t1 = new Thread(pGroup, this); t1.setPriority(Thread.MAX_PRIORITY); System.out.println("Starting " + t1.getName()); t1.start();/*from w w w . j a v a 2 s .c o m*/ Thread t2 = new Thread(cGroup, this); t1.setPriority(Thread.MAX_PRIORITY); System.out.println("Starting " + t2.getName()); t2.start(); System.out.println("Active threads in \"" + pGroup.getName() + "\" = " + pGroup.activeCount()); }
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;/*from w ww .ja v a2 s . co m*/ 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:net.sourceforge.vulcan.jabber.SmackKeepAliveThreadInterrupter.java
public void interrupt() { final ThreadGroup group = Thread.currentThread().getThreadGroup(); final Thread[] threads = new Thread[group.activeCount()]; group.enumerate(threads);/* ww w . j av a2 s.c o m*/ for (Thread thread : threads) { if (!thread.getName().startsWith("Smack Keep Alive")) { continue; } if (!thread.getContextClassLoader().equals(getClass().getClassLoader())) { // only wake up threads from our own class loader LOG.info("Not waking up " + thread.getName() + " because it uses a different class loader."); continue; } LOG.info("Interrupting " + thread.getName()); thread.interrupt(); try { thread.join(1000); } catch (InterruptedException ignore) { } if (thread.isAlive()) { LOG.error("Smack Keep Alive thread still alive after interruption."); } } }
From source file:org.synchronoss.cloud.nio.multipart.example.utils.ContextFinalizer.java
@Override public void onApplicationEvent(ContextClosedEvent event) { if (log.isInfoEnabled()) log.info("onApplicationEvent: " + event); Enumeration<Driver> drivers = DriverManager.getDrivers(); Driver driver = null;/*from ww w.j av a 2 s .co m*/ while (drivers.hasMoreElements()) { try { driver = drivers.nextElement(); DriverManager.deregisterDriver(driver); if (log.isWarnEnabled()) log.warn(String.format("Driver %s unregistered", driver)); } catch (SQLException e) { if (log.isWarnEnabled()) log.warn(String.format("Error unregistering driver %s", driver), e); } } Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); for (Thread thread : threadArray) { if (thread.getName().contains("Abandoned connection cleanup thread")) { synchronized (thread) { thread.stop(); //don't complain, it works } } } if (log.isInfoEnabled()) log.info("Finished processing onApplicationEvent"); }