KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > scheduling > timer > DelegatingTimerTask


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.scheduling.timer;
18
19 import java.util.TimerTask JavaDoc;
20
21 import org.springframework.util.Assert;
22
23 /**
24  * Simple TimerTask adapter that delegates to a given Runnable.
25  *
26  * <p>This is often preferable to deriving from TimerTask, to be able to
27  * implement an interface rather than extend an abstract base class.
28  *
29  * @author Juergen Hoeller
30  * @since 1.2.4
31  * @see java.util.TimerTask
32  * @see java.lang.Runnable
33  */

34 public class DelegatingTimerTask extends TimerTask JavaDoc {
35
36     private final Runnable JavaDoc delegate;
37
38
39     /**
40      * Create a new DelegatingTimerTask.
41      * @param delegate the Runnable implementation to delegate to
42      */

43     public DelegatingTimerTask(Runnable JavaDoc delegate) {
44         Assert.notNull(delegate, "Delegate must not be null");
45         this.delegate = delegate;
46     }
47
48     /**
49      * Return the wrapped Runnable implementation.
50      */

51     public final Runnable JavaDoc getDelegate() {
52         return delegate;
53     }
54
55
56     /**
57      * Delegates execution to the underlying Runnable.
58      */

59     public void run() {
60         this.delegate.run();
61     }
62
63 }
64
Popular Tags