001: /*
002: *
003: * Jsmtpd, Java SMTP daemon
004: * Copyright (C) 2005 Jean-Francois POUX, jf.poux@laposte.net
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021: package org.jsmtpd.generic.threadpool;
022:
023: /**
024: * @author Jean-Francois POUX
025: * Jsmtpd
026: */
027: public class ThreadPoolTest {
028:
029: public static void main(String[] args) throws InterruptedException {
030: ThreadPool pool = null;
031: try {
032: pool = new GenericThreadPool(20,
033: "org.jsmtpd.generic.threadpool.DummyThread",
034: "Dummy");
035: } catch (InstantiationException e) {
036: e.printStackTrace();
037: } catch (IllegalAccessException e) {
038: e.printStackTrace();
039: } catch (ClassNotFoundException e) {
040:
041: e.printStackTrace();
042: }
043:
044: // for (int i=0;i<20;i++) {
045: // try {
046: // pool.assignFreeThread("Test !");
047: // } catch (BusyThreadPoolException e) {
048: // e.printStackTrace();
049: // }
050: // }
051: // Thread.sleep(30000);
052: int cp = 0;
053: while (cp < 100) {
054: for (int i = 0; i < 20; i++) {
055: try {
056: pool.assignFreeThread("Test !");
057: } catch (BusyThreadPoolException e) {
058: }
059: }
060: Thread.sleep(3000);
061: cp++;
062: }
063: Thread.sleep(30000);
064: /*
065: try {
066: System.out.println("Assigning 1, pool can handle " + pool.countFreeThread());
067: pool.assignFreeThread("Test !");
068: System.out.println("Assigned 1");
069: } catch (BusyThreadPoolException e2) {
070:
071: e2.printStackTrace();
072: }
073: */
074: /*
075: System.out.println("main Go sleep");
076: try {
077: Thread.sleep(300);
078: } catch (InterruptedException e1) {
079: e1.printStackTrace();
080: }
081: System.out.println("main wake");*/
082: pool.forceShutdown();
083: System.err.println("pool down");
084: /*
085: try {
086: System.out.println("Assigning 2, pool can handle "+pool.countFreeThread());
087: pool.assignFreeThread("Test2 !");
088: System.out.println("Assigned 2");
089: } catch (BusyThreadPoolException e2) {
090: e2.printStackTrace();
091: }
092: */
093: System.out.println("main Go sleep");
094: try {
095: Thread.sleep(10000);
096: } catch (InterruptedException e1) {
097: e1.printStackTrace();
098: }
099: System.out.println("main wake");
100: pool.forceShutdown();
101: System.out.println("pool clean");
102:
103: }
104: }
|