KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jsmtpd > generic > threadpool > ThreadPoolTest


1 /*
2  *
3  * Jsmtpd, Java SMTP daemon
4  * Copyright (C) 2005 Jean-Francois POUX, jf.poux@laposte.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  */

21 package org.jsmtpd.generic.threadpool;
22
23 /**
24  * @author Jean-Francois POUX
25  * Jsmtpd
26  */

27 public class ThreadPoolTest {
28
29     public static void main(String JavaDoc[] args) throws InterruptedException JavaDoc {
30         ThreadPool pool = null;
31         try {
32             pool = new GenericThreadPool(20, "org.jsmtpd.generic.threadpool.DummyThread","Dummy");
33         } catch (InstantiationException JavaDoc e) {
34             e.printStackTrace();
35         } catch (IllegalAccessException JavaDoc e) {
36             e.printStackTrace();
37         } catch (ClassNotFoundException JavaDoc e) {
38
39             e.printStackTrace();
40         }
41
42 // for (int i=0;i<20;i++) {
43
// try {
44
// pool.assignFreeThread("Test !");
45
// } catch (BusyThreadPoolException e) {
46
// e.printStackTrace();
47
// }
48
// }
49
// Thread.sleep(30000);
50
int cp=0;
51         while (cp<100) {
52             for (int i=0;i<20;i++) {
53                 try {
54                     pool.assignFreeThread("Test !");
55                 } catch (BusyThreadPoolException e) {
56                 }
57             }
58             Thread.sleep(3000);
59             cp++;
60         }
61         Thread.sleep(30000);
62         /*
63         try {
64             System.out.println("Assigning 1, pool can handle " + pool.countFreeThread());
65             pool.assignFreeThread("Test !");
66             System.out.println("Assigned 1");
67         } catch (BusyThreadPoolException e2) {
68
69             e2.printStackTrace();
70         }
71         */

72         /*
73          System.out.println("main Go sleep");
74          try {
75          Thread.sleep(300);
76          } catch (InterruptedException e1) {
77          e1.printStackTrace();
78          }
79          System.out.println("main wake");*/

80         pool.forceShutdown();
81         System.err.println("pool down");
82         /*
83          try {
84          System.out.println("Assigning 2, pool can handle "+pool.countFreeThread());
85          pool.assignFreeThread("Test2 !");
86          System.out.println("Assigned 2");
87          } catch (BusyThreadPoolException e2) {
88          e2.printStackTrace();
89          }
90          */

91         System.out.println("main Go sleep");
92         try {
93             Thread.sleep(10000);
94         } catch (InterruptedException JavaDoc e1) {
95             e1.printStackTrace();
96         }
97         System.out.println("main wake");
98         pool.forceShutdown();
99         System.out.println("pool clean");
100
101     }
102 }
Popular Tags