01: /*
02: * HA-JDBC: High-Availability JDBC
03: * Copyright (c) 2004-2007 Paul Ferraro
04: *
05: * This library is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU Lesser General Public License as published by the
07: * Free Software Foundation; either version 2.1 of the License, or (at your
08: * option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13: * for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public License
16: * along with this library; if not, write to the Free Software Foundation,
17: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * Contact: ferraro@users.sourceforge.net
20: */
21: package net.sf.hajdbc.util.concurrent;
22:
23: import java.util.Collections;
24: import java.util.List;
25: import java.util.concurrent.AbstractExecutorService;
26: import java.util.concurrent.TimeUnit;
27:
28: /**
29: * Executor service that executes tasks in the caller thread.
30: *
31: * @author Paul Ferraro
32: */
33: public class SynchronousExecutor extends AbstractExecutorService {
34: private boolean shutdown;
35:
36: /**
37: * @see java.util.concurrent.ExecutorService#awaitTermination(long, java.util.concurrent.TimeUnit)
38: */
39: @Override
40: public boolean awaitTermination(long time, TimeUnit unit) {
41: return true;
42: }
43:
44: /**
45: * @see java.util.concurrent.ExecutorService#isShutdown()
46: */
47: @Override
48: public boolean isShutdown() {
49: return this .shutdown;
50: }
51:
52: /**
53: * @see java.util.concurrent.ExecutorService#isTerminated()
54: */
55: @Override
56: public boolean isTerminated() {
57: return this .shutdown;
58: }
59:
60: /**
61: * @see java.util.concurrent.ExecutorService#shutdown()
62: */
63: @Override
64: public void shutdown() {
65: this .shutdown = true;
66: }
67:
68: /**
69: * @see java.util.concurrent.ExecutorService#shutdownNow()
70: */
71: @Override
72: public List<Runnable> shutdownNow() {
73: this .shutdown();
74:
75: return Collections.emptyList();
76: }
77:
78: /**
79: * @see java.util.concurrent.Executor#execute(java.lang.Runnable)
80: */
81: @Override
82: public void execute(Runnable task) {
83: task.run();
84: }
85: }
|