/** * Start this server. If we manage an own HttpServer, then the HttpServer will be started as well. */ public void start() { // URL as configured takes precedence String configUrl = NetworkUtil.replaceExpression(config.getJolokiaConfig().get(ConfigKey.DISCOVERY_AGENT_URL)); jolokiaHttpHandler.start( lazy, configUrl != null ? configUrl : url, config.getAuthenticator() != null); if (httpServer != null) { // Starting our own server in an own thread group with a fixed name // so that the cleanup thread can recognize it. ThreadGroup threadGroup = new ThreadGroup("jolokia"); threadGroup.setDaemon(false); Thread starterThread = new Thread( threadGroup, new Runnable() { @Override public void run() { httpServer.start(); } }); starterThread.start(); cleaner = new CleanupThread(httpServer, threadGroup); cleaner.start(); } }
/** * Returns an array containing the existing client connections. This can be used by concrete * subclasses to implement messages that do something with each connection (e.g. kill it, send a * message to it etc.). Remember that after this array is obtained, some clients in this migth * disconnect. New clients can also connect, these later will not appear in the array. * * @return an array of <code>Thread</code> containing <code>ConnectionToClient</code> instances. */ public final synchronized Thread[] getClientConnections() { Thread[] clientThreadList = new Thread[clientThreadGroup.activeCount()]; clientThreadGroup.enumerate(clientThreadList); return clientThreadList; }
/** Helper method for main to load tests into a thread group and start each test case. */ private static void loadThread(String name) { try { ThreadGroup myThreadGroup = new ThreadGroup(name); String urlSpec = "http://54.201.122.231:8181/v4/gumball"; // String urlSpec = "http://localhost:8080/v4/gumball" ; RunLoadTest test = new RunLoadTest(myThreadGroup, urlSpec); test.runTest(); // Run The Test in its own thread myThreadGroup.list(); } catch (Exception e) { System.out.println("ERROR: " + e.getMessage()); } }
private Runner getRunner() { try { return (Runner) threadpool.pop(); } catch (EmptyStackException empty) { if (runners.activeCount() > 255) throw new RuntimeException("System overload"); return new Runner(); } }
public static void main(String args[]) { try { ServerSocket serv = new ServerSocket(8080); System.out.println("showserver created at port 8080."); ThreadGroup workers = new ThreadGroup("WebWorkers"); while (true) { if (workers.activeCount() < maxCon) { System.out.println("Hay " + workers.activeCount() + " hebras corriendo."); Socket conn = serv.accept(); Thread hs = new Thread(workers, new HebraServ(conn)); hs.start(); } else { try { Thread.sleep(500); } catch (Exception ex) { } } } } catch (IOException e) { System.err.println(e); } }
public static boolean kill() { int j = 0; Thread meMySelfI = Thread.currentThread(); do { /* iter across the thread group, killing all members. */ shutdown = true; Thread list[] = new Thread[tg.activeCount()]; // get all members of the group (including submembers) int i = tg.enumerate(list); // no members means that we have gracefully suceeded if (i == 0) return true; // if some of the threads do IO during the shut down they will // need time to accomplish the IO. So, I give it to 'em // after the first attempt. if (j > 0) try { meMySelfI.sleep(500); } catch (Exception e) { } ; // try to shudown each thread in the group while (i-- > 0) { FlickrFtpd tftp = (FlickrFtpd) list[i]; tftp.interrupt(); // first, do it politely meMySelfI.yield(); // give 'em time to respond tftp.forceClose(); // second, use a big hammer meMySelfI.yield(); // give 'em time to respond } } while (j++ <= 3); return false; }
/** * Counts the number of clients currently connected. * * @return the number of clients currently connected. */ public final int getNumberOfClients() { return clientThreadGroup.activeCount(); }