private synchronized ThreadPool getPool() { if (pool == null) pool = new ThreadPool (1, 10); return pool; }
public boolean process (ISOSource source, ISOMsg m) { if (pool == null) pool = new ThreadPool (1, 10); pool.execute (new Process (source, m)); return true; } }
/** * @param port port to listen * @param clientSide client side ISOChannel (where we accept connections) * @param pool ThreadPool (created if null) */ public ISOServer(int port, ServerChannel clientSide, ThreadPool pool) { super(); this.port = port; this.clientSideChannel = clientSide; this.clientPackager = clientSide.getPackager(); if (clientSide instanceof FilteredChannel) { FilteredChannel fc = (FilteredChannel) clientSide; this.clientOutgoingFilters = fc.getOutgoingFilters(); this.clientIncomingFilters = fc.getIncomingFilters(); } this.pool = pool == null ? new ThreadPool (1, DEFAULT_MAX_THREADS) : pool; listeners = new Vector(); name = ""; channels = new HashMap(); cnt = new int[SIZEOF_CNT]; serverListeners = new ArrayList<ISOServerEventListener>(); }
@Test public void testDump3() throws Throwable { new LogEvent(new ThreadPool(0, 0), "testString", null).dump(new PrintStream(new ByteArrayOutputStream(), true), "a42"); assertEquals("\"a42\"", "a42", "a42"); }
public void setConfiguration (Configuration cfg) throws ConfigurationException { this.cfg = cfg; try { mux = (SpaceMUX) NameRegistrar.get (cfg.get ("mux")); } catch (NotFoundException e) { throw new ConfigurationException (e); } timeout = cfg.getLong ("timeout", 120000); pool = new ThreadPool (1, cfg.getInt ("pool", 100)); }
@Ignore @Test public void testConcurrentThreadAllocation() throws Throwable { ThreadPool pool = new ThreadPool(1, 200, "Test-ThreadPool"); Server server = new Server(pool); Thread serverThread = new Thread(server); serverThread.start(); serverThread.join(15000); assertEquals("pool.getActiveCount()", 100, pool.getActiveCount()); synchronized (server) { server.notifyAll(); } pool.close(); }
/** * Destination can be a Channel or a MUX. If Destination is a Channel * then timeout applies (used on ISORequest to get a Response). * <ul> * <li>destination-mux * <li>destination-channel * <li>timeout * <li>poolsize * </ul> * @param cfg Configuration */ public void setConfiguration (Configuration cfg) throws ConfigurationException { timeout = cfg.getInt ("timeout"); if (pool == null) pool = new ThreadPool (1, cfg.getInt ("poolsize", 10)); muxName = cfg.get ("destination-mux", null); channelName = cfg.get ("destination-channel", null); preserveSourceHeader = cfg.getBoolean ("preserve-source-header", true); if (muxName == null && channelName == null) { throw new ConfigurationException("Neither destination mux nor channel were specified."); } }
@Test @SuppressWarnings("deprecation") public void testIssue196 () { ThreadPool pool = new ThreadPool(10, 20, "thepool"); int available = pool.getAvailableCount(); int active = pool.getActiveCount(); long end = System.currentTimeMillis() + 10000L; // run for 10 seconds top int i = 0; while (active >= 0 && System.currentTimeMillis() < end) { while (available > 0) { pool.execute(() -> { }); available = pool.getAvailableCount(); } available = pool.getAvailableCount(); active = pool.getActiveCount(); } assertTrue ("Active should be >= 0 but it is " + active, active >= 0); }
private ISOServer newIsoServer() throws IOException, ISOException { XMLChannel clientSide = new XMLChannel(new XMLPackager()); clientSide.setLogger(logger, "server.channel"); ISOServer isoServer = new ISOServer(PORT, clientSide, new ThreadPool()); isoServer.setSocketFactory(new SunJSSESocketFactory()); isoServer.setConfiguration(serverConfiguration()); isoServer.setLogger(logger, "server"); isoServer.addISORequestListener(new TestListener()); return isoServer; }
@Test public void testConstructor() throws Throwable { ThreadPool threadPool = new ThreadPool(-1, 1); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 1, threadPool.getMaxPoolSize()); }
@Test public void testConstructor2() throws Throwable { ThreadPool threadPool = new ThreadPool(0, 100); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); }
@Test public void testConstructor1() throws Throwable { ThreadPool threadPool = new ThreadPool(-2, -1); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); }
@Test public void testConstructor3() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 0); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); }
@Test public void testConstructor4() throws Throwable { ThreadPool threadPool = new ThreadPool(2, 100); assertEquals("threadPool.getJobCount()", 0, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 2, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); }
@Test public void testRunNames() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 2); threadPool.execute(new TestTask()); ISOUtil.sleep(20); threadPool.execute(new TestTask()); ISOUtil.sleep(20); Thread[] tl = new Thread[threadPool.activeCount()]; threadPool.enumerate(tl); for (Thread t :tl ) assertThat(t.getName(), new Matches("ThreadPool.PooledThread-\\d+-(running|idle)")); }
pool = new ThreadPool (minSessions ,maxSessions, getName() + "-ThreadPool"); pool.setLogger (log.getLogger(), getName() + ".pool");
@Test public void testRun3() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 2); threadPool.execute(new TestTask()); ISOUtil.sleep(20); threadPool.execute(new TestTask()); ISOUtil.sleep(20); assertEquals("threadPool.getJobCount()", 2, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 2, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 2, threadPool.getMaxPoolSize()); }
@Test public void testRun1() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 100); ISOUtil.sleep(50); threadPool.execute(new TestTask()); ISOUtil.sleep(50); assertEquals("threadPool.getJobCount()", 1, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 100, threadPool.getMaxPoolSize()); ISOUtil.sleep(500); assertEquals("threadPool.getJobCount()", 1, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); }
protected void initService () throws Exception { QFactory factory = getServer().getFactory(); dirPoll = createDirPoll(); dirPoll.setPath (getPath ()); dirPoll.setThreadPool (new ThreadPool (1, poolSize)); dirPoll.setPollInterval (pollInterval); if (priorities != null) dirPoll.setPriorities (priorities); dirPoll.setLogger (getLog().getLogger(), getLog().getRealm ()); Configuration cfg = factory.getConfiguration (getPersist()); dirPoll.setConfiguration (cfg); dirPoll.createDirs (); Object dpp = factory.newInstance (getProcessor()); if (dpp instanceof LogSource) { ((LogSource) dpp).setLogger ( getLog().getLogger(), getLog().getRealm () ); } if (dpp instanceof Configurable) { ((Configurable) dpp).setConfiguration (cfg); } dirPoll.setProcessor (dpp); }
@Test public void testRun2() throws Throwable { ThreadPool threadPool = new ThreadPool(1, 1); threadPool.execute(new TestTask()); threadPool.execute(new TestTask()); ISOUtil.sleep(50); assertEquals("threadPool.getJobCount()", 2, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 1, threadPool.getMaxPoolSize()); assertEquals("threadPool.getPendingCount()", 1, threadPool.getPendingCount()); ISOUtil.sleep(500); assertEquals("threadPool.getJobCount()", 2, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getPendingCount()", 0, threadPool.getPendingCount()); assertEquals("threadPool.getMaxPoolSize()", 1, threadPool.getMaxPoolSize()); ISOUtil.sleep(550); assertEquals("threadPool.getJobCount()", 2, threadPool.getJobCount()); assertEquals("threadPool.getPoolSize()", 1, threadPool.getPoolSize()); assertEquals("threadPool.getMaxPoolSize()", 1, threadPool.getMaxPoolSize()); }