1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package twcsckernel.projectbase.rmi.socketfactory;
16
17 import java.io.*;
18 import java.net.*;
19 import java.util.*;
20
21 /***
22 * Provides a simple producer/consumer pool of sockets.
23 *
24 * @author Tim Taylor -- tttaylor@cssassociates.com
25 */
26 public class SocketPool {
27 private LinkedList<Socket> socketList = new LinkedList<Socket>();
28
29 public synchronized Socket getSocket() throws InterruptedIOException {
30 try {
31 while (socketList.isEmpty()) {
32 this.wait();
33 }
34 }
35 catch (InterruptedException e) {
36 throw new InterruptedIOException();
37 }
38
39 return (Socket) socketList.removeFirst();
40 }
41
42 public synchronized void addSocket(Socket socket) {
43 socketList.add(socket);
44 this.notifyAll();
45 }
46 }
47