01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1997-2004 Gerald Brose.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Library General Public License for more details.
15: *
16: * You should have received a copy of the GNU Library General Public
17: * License along with this library; if not, write to the Free
18: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19: */
20:
21: package org.jacorb.util.threadpool;
22:
23: /**
24: * ConsumerTie.java
25: *
26: * @author Nicolas Noffke
27: * $Id: ConsumerTie.java,v 1.12 2006/06/20 15:26:04 alphonse.bendt Exp $
28: */
29:
30: public class ConsumerTie implements Runnable {
31: private final ThreadPool pool;
32: private final Consumer delegate;
33:
34: public ConsumerTie(ThreadPool pool, Consumer delegate) {
35: this .pool = pool;
36: this .delegate = delegate;
37: }
38:
39: public void run() {
40: while (true) {
41: try {
42: Object job = pool.getJob();
43:
44: if (job == null) {
45: /*
46: * job == null is sent by the pool, if there are
47: * too much idle threads. Therefore we exit.
48: */
49: break;
50: }
51:
52: delegate.doWork(job);
53: } catch (Exception e) {
54: pool.getLogger().debug("ConsumerTie caught", e);
55: }
56: }
57: pool.getLogger().info("ConsumerTie exited");
58: }
59: } // ConsumerTie
|