- public synchronized void start(Runnable r) {
- /* if no idle threads, wait for MINIMUM_DISPATCH_DELAY or until notified */
- if (numIdleThreads == 0) try {
- this.wait(MINIMUM_DISPATCH_DELAY);
- } catch (Exception e) { Log.error(this, e); }
-
- /* if there are idle threads, use one */
- if (numIdleThreads > 0) {
- numIdleThreads--;
- idleThreads[numIdleThreads].start(r);
- idleThreads[numIdleThreads] = null;
- return;
+ public void start(Runnable r) {
+ synchronized(ThreadPool.this) {
+ /* if no idle threads, wait for MINIMUM_DISPATCH_DELAY or until notified */
+ if (numIdleThreads == 0) try {
+ this.wait(MINIMUM_DISPATCH_DELAY);
+ } catch (Exception e) { Log.error(this, e); }
+
+ /* if there are idle threads, use one */
+ if (numIdleThreads > 0) {
+ numIdleThreads--;
+ idleThreads[numIdleThreads].start(r);
+ idleThreads[numIdleThreads] = null;
+ return;
+ }
+ /* otherwise, create a new thread */
+ numThreads++;