001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.core.task.support;
018
019import java.util.concurrent.Executor;
020
021import org.springframework.core.task.TaskExecutor;
022import org.springframework.util.Assert;
023
024/**
025 * Adapter that exposes the {@link java.util.concurrent.Executor} interface
026 * for any Spring {@link org.springframework.core.task.TaskExecutor}.
027 *
028 * <p>This is less useful as of Spring 3.0, since TaskExecutor itself
029 * extends the Executor interface. The adapter is only relevant for
030 * <em>hiding</em> the TaskExecutor nature of a given object now,
031 * solely exposing the standard Executor interface to a client.
032 *
033 * @author Juergen Hoeller
034 * @since 2.5
035 * @see java.util.concurrent.Executor
036 * @see org.springframework.core.task.TaskExecutor
037 */
038public class ConcurrentExecutorAdapter implements Executor {
039
040        private final TaskExecutor taskExecutor;
041
042
043        /**
044         * Create a new ConcurrentExecutorAdapter for the given Spring TaskExecutor.
045         * @param taskExecutor the Spring TaskExecutor to wrap
046         */
047        public ConcurrentExecutorAdapter(TaskExecutor taskExecutor) {
048                Assert.notNull(taskExecutor, "TaskExecutor must not be null");
049                this.taskExecutor = taskExecutor;
050        }
051
052
053        @Override
054        public void execute(Runnable command) {
055                this.taskExecutor.execute(command);
056        }
057
058}