Debian Codegraph @

src/main/java/net/sf/antcontrib/util/ThreadPool.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.antcontrib.util;
17
18 /****************************************************************************
19 * Place class description here.
20 *
21 * @author <a href='mailto:[email protected]'>Matthew Inger</a>
22 *
23 ****************************************************************************/
24
25
26 public class ThreadPool
27 {
28 private int maxActive;
29 private int active;
30
31
32 public ThreadPool(int maxActive)
33 {
34 super();
35 this.maxActive = maxActive;
36 this.active = 0;
37 }
38
39 public void returnThread(ThreadPoolThread thread)
40 {
41 synchronized (this)
42 {
43 active--;
44 notify();
45 }
46 }
47
48
49 public ThreadPoolThread borrowThread()
50 throws InterruptedException
51 {
52 synchronized (this)
53 {
54 if (maxActive > 0 && active >= maxActive)
55 {
56 wait();
57 }
58
59 active++;
60 return new ThreadPoolThread(this);
61 }
62 }
63 }