All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jetty.util.thread.strategy.ExecutingExecutionStrategy Maven / Gradle / Ivy

There is a newer version: 12.1.0.alpha1
Show newest version
//
//  ========================================================================
//  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
//  ------------------------------------------------------------------------
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//

package org.eclipse.jetty.util.thread.strategy;

import java.io.Closeable;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;

import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ExecutionStrategy;

/**
 * 

Base class for strategies that need to execute a task by submitting it to an {@link Executor}.

*

If the submission to the {@code Executor} is rejected (via a {@link RejectedExecutionException}), * the task is tested whether it implements {@link Closeable}; if it does, then {@link Closeable#close()} * is called on the task object.

*/ public abstract class ExecutingExecutionStrategy implements ExecutionStrategy { private static final Logger LOG = Log.getLogger(ExecutingExecutionStrategy.class); private final Executor _executor; protected ExecutingExecutionStrategy(Executor executor) { _executor=executor; } protected boolean execute(Runnable task) { try { _executor.execute(task); return true; } catch(RejectedExecutionException e) { // If we cannot execute, then close the task and keep producing. LOG.debug(e); LOG.warn("Rejected execution of {}",task); try { if (task instanceof Closeable) ((Closeable)task).close(); } catch (Exception x) { e.addSuppressed(x); LOG.warn(e); } } return false; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy