KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > jca > workmanager > ResourceWorkThread


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 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  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ResourceWorkThread.java 1140 2006-10-06 09:21:59Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.jca.workmanager;
27
28 import javax.resource.spi.work.WorkException JavaDoc;
29
30 import org.objectweb.easybeans.log.JLog;
31 import org.objectweb.easybeans.log.JLogFactory;
32
33 /**
34  * Thread executing works for the work manager.
35  * @author Philippe Durieux (JOnAS)
36  * @author Florent Benoit (EasyBeans)
37  */

38 public class ResourceWorkThread extends Thread JavaDoc {
39
40     /**
41      * Logger.
42      */

43     private JLog logger = JLogFactory.getLog(ResourceWorkThread.class);
44
45     /**
46      * Resource WorkManager used by this worker thread.
47      */

48     private ResourceWorkManager workManager;
49
50     /**
51      * Build a thread doing the work.
52      * @param workManager The implementation of WorkManager API.
53      * @param threadNumber the thread number for this thread (debug info)
54      * @param workManagerNumber identifier of the work manager instance
55      */

56     ResourceWorkThread(final ResourceWorkManager workManager, final int workManagerNumber, final int threadNumber) {
57         this.workManager = workManager;
58         setName(this.getClass().getName() + "-" + workManagerNumber + "/" + threadNumber);
59     }
60
61     /**
62      * Start the thread work.
63      */

64     @Override JavaDoc
65     public void run() {
66
67         while (true) {
68             try {
69                 workManager.nextWork();
70             } catch (InterruptedException JavaDoc e) {
71                 logger.error("Exception while waiting during a work", e);
72                 return;
73             } catch (WorkException JavaDoc e) {
74                 logger.error("Exception during work run", e);
75             } catch (ResourceWorkManagerStoppedException e) {
76                 logger.debug("Manager has been stopped", e);
77                 return;
78             }
79         }
80     }
81 }
82
Popular Tags