KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > connectionmanager > PoolFiller


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.resource.connectionmanager;
23
24 import java.util.LinkedList JavaDoc;
25
26 /**
27  * PoolFiller
28  *
29  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
30  * @author Scott.Stark@jboss.org
31  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
32  * @version $Revision: 38338 $
33  */

34 public class PoolFiller implements Runnable JavaDoc
35 {
36    private final LinkedList JavaDoc pools = new LinkedList JavaDoc();
37
38    private final Thread JavaDoc fillerThread;
39
40    private static final PoolFiller filler = new PoolFiller();
41
42    public static void fillPool(InternalManagedConnectionPool mcp)
43    {
44       filler.internalFillPool(mcp);
45    }
46
47    public PoolFiller ()
48    {
49       fillerThread = new Thread JavaDoc(this, "JCA PoolFiller");
50       fillerThread.start();
51    }
52
53    public void run()
54    {
55       ClassLoader JavaDoc myClassLoader = getClass().getClassLoader();
56       Thread.currentThread().setContextClassLoader(myClassLoader);
57       //keep going unless interrupted
58
while (true)
59       {
60          try
61          {
62             InternalManagedConnectionPool mcp = null;
63             //keep iterating through pools till empty, exception escapes.
64
while (true)
65             {
66                      
67                synchronized (pools)
68                {
69                   mcp = (InternalManagedConnectionPool)pools.removeFirst();
70                }
71                if (mcp == null)
72                   break;
73                         
74                mcp.fillToMin();
75             }
76          }
77          catch (Exception JavaDoc e)
78          {
79          }
80                         
81          try
82          {
83             synchronized (pools)
84             {
85                pools.wait();
86             }
87          }
88          catch (InterruptedException JavaDoc ie)
89          {
90             return;
91          }
92       }
93    }
94
95    private void internalFillPool(InternalManagedConnectionPool mcp)
96    {
97       synchronized (pools)
98       {
99          pools.addLast(mcp);
100          pools.notify();
101       }
102    }
103 }
104
Popular Tags