2004/05/19 xchen fix bug 55542 - [IM Event Gateway] EventService.AddEvent log message always contains useless null string. It seems that the reason is QueueSizeExceeded exception doesn't have detailed message. "Error","Smack Listener Processor","05/17/04","13:54:27",, "Problem adding event for gateway XMPP jabberd - mousemail: null" fix the QueueSizeExceeded to be ApplicationException type < public class QueueSizeExceeded extends Exception -> public class QueueSizeExceeded extends ApplicationException { public int size = -1; public QueueSizeExceeded(int queuesize) { super(); size = queuesize; } } 02/27/04: Tom Jordahl Fix up comments and remove LGPL copyright. /** < * Created by Tom Jordahl -> * -> * This is a thread pool for Java, it is -> * simple to use and gets the job done. -> * -> * Copyright 2001 by Jeff Heaton -> * Provided to Macromedia under the Apache license * < * Date: Nov 17, 2003 < * Time: 3:05:56 PM < * adding simple Java Thread Pool in the util package -> * @author Jeff Heaton (http://www.jeffheaton.com) -> * @version 1.0 */ < /** < * < * This is a thread pool for Java, it is < * simple to use and gets the job done. This program and < * all supporting files are distributed under the Limited < * GNU Public License (LGPL, http://www.gnu.org). < * * This is a very simple object that * allows the TheadPool to determine when * it is done. This object implements * a simple lock that the ThreadPool class * can wait on to determine completion. * Done is defined as the ThreadPool having * no more work to complete. * < * Copyright 2001 by Jeff Heaton < * < * @author Jeff Heaton (http://www.jeffheaton.com) < * @version 1.0 */ < 12/16/03: xchen change miss wording found by Tom J /** * A problem occurred when attempting to add more assignments into the threadpool task queue. < * There is no space left in the queue to take more task. Queue size is currently set to {size}. -> * There is no space left in the queue to accept another task. Queue size is currently set to {size}. * @author Xu Chen */ 12/15/03: xchen update threadpool to handle linklist < import java.util.*; -> import java.util.LinkedList; -> /** * The backlog of assignments, which are waiting * for the thread pool. -> * -> * Replace with LinkedList instead of ArrayList due to efficiency concern -> * this is double pointer linklist which can shrink easily but take more size. */ < Collection assignments = new ArrayList(50); -> LinkedList assignments = new LinkedList(); -> -> -> int queuesizelimit = -1; -> -> /** -> * The constructor. which take both threadpool size and queue size -> * -> * @param size How many threads in the thread pool. -> */ -> public SimpleThreadPool(int size, int queuesize) -> { -> threads = new SimpleWorkerThread[size]; -> for (int i=0;i { -> threads[i] = new SimpleWorkerThread(this); -> threads[i].start(); -> } -> -> queuesizelimit = queuesize; -> } -> -> /** * Add a task to the thread pool. Any class * which implements the Runnable interface * may be assienged. When this task runs, its * run method will be called. * -> * if we do not assign a queuesize or our queuesize -> * is smaller than limit size then we can add to assignment queue. -> * Otherwise, we drop the request. -> * -> * * @param r An object that implements the Runnable interface -> * @throws Exception -- indicating we are dropping messages -> * */ < public synchronized void assign(Runnable r) -> public synchronized void assign(Runnable r) throws Exception { < done.workerBegin(); < assignments.add(r); < notify(); -> if(queuesizelimit == -1 || queuesizelimit > assignments.size() ) -> { -> done.workerBegin(); -> assignments.addLast(r); -> notify(); -> }else -> { -> throw new QueueSizeExceeded(queuesizelimit); -> } } public synchronized Runnable getAssignment() { try { while ( !assignments.iterator().hasNext() ) wait(); //wait until there is work < Runnable r = (Runnable)assignments.iterator().next(); < assignments.remove(r); -> Runnable r = (Runnable)assignments.removeFirst(); return r; } catch (InterruptedException e) { done.workerEnd(); return null; } } -> -> /** -> * A problem occurred when attempting to add more assignments into the threadpool task queue. -> * There is no space left in the queue to take more task. Queue size is currently set to {size}. -> * @author Xu Chen -> */ -> public class QueueSizeExceeded extends Exception -> { -> public int size = -1; -> public QueueSizeExceeded(int queuesize) -> { -> super(); -> size = queuesize; -> } -> } ->