Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2013 Ning, Inc.
   *
   * Ning licenses this file to you under the Apache License, version 2.0
   * (the "License"); you may not use this file except in compliance with the
   * License.  You may obtain a copy of the License at:
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
  * License for the specific language governing permissions and limitations
  * under the License.
  */
 
 package com.ning.billing.commons.concurrent;
 
 
Extension of java.util.concurrent.ScheduledThreadPoolExecutor that will continue to schedule a task even if the previous run had an exception. Also ensures that uncaught exceptions are logged.
 
 
     private static final Logger LOG = LoggerFactory.getLogger(FailsafeScheduledExecutor.class);

    
Creates a new single-threaded executor with a NamedThreadFactory of the given name.

Parameters:
name thread name base
 
     public FailsafeScheduledExecutor(final String name) {
         this(1, name);
     }

    
Creates a new executor with a NamedThreadFactory of the given name.

Parameters:
corePoolSize number of threads in the pool
name thread name base
 
     public FailsafeScheduledExecutor(final int corePoolSizefinal String name) {
         this(corePoolSizenew NamedThreadFactory(name));
     }

    
Creates a new executor with the given thread factory.

Parameters:
corePoolSize number of threads in the pool
threadFactory a thread factory to use
 
     public FailsafeScheduledExecutor(final int corePoolSizefinal ThreadFactory threadFactory) {
         super(corePoolSizethreadFactory);
     }

    
Creates a new executor with the given thread factory.

Parameters:
corePoolSize number of threads in the pool
name thread name base
handler a rejected execution handler to use
 
     public FailsafeScheduledExecutor(final int corePoolSizefinal String namefinal RejectedExecutionHandler handler) {
         super(corePoolSizenew NamedThreadFactory(name), handler);
     }

    
Creates a new executor with the given thread factory.

Parameters:
corePoolSize number of threads in the pool
threadFactory a thread factory to use
handler a rejected execution handler to use
 
     public FailsafeScheduledExecutor(final int corePoolSizefinal ThreadFactory threadFactoryfinal RejectedExecutionHandler handler) {
         super(corePoolSizethreadFactoryhandler);
     }
 
     @Override
     public <T> Future<T> submit(final Callable<T> task) {
         return super.submit(WrappedCallable.wrap(task));
     }
 
     @Override
     public <T> Future<T> submit(final Runnable taskfinal T result) {
         // HACK: assumes ScheduledThreadPoolExecutor will create a callable and call schedule()
         // (can't wrap the runnable here or exception isn't re-thrown when Future.get() is called)
         return super.submit(taskresult);
     }
    @Override
    public Future<?> submit(final Runnable task) {
        return super.submit(WrappedRunnable.wrap(task));
    }
    @Override
    public void execute(final Runnable command) {
        super.execute(WrappedRunnable.wrap(command));
    }
    @Override
    public ScheduledFuture<?> scheduleWithFixedDelay(final Runnable commandfinal long initialDelayfinal long delayfinal TimeUnit unit) {
        return super.scheduleWithFixedDelay(WrappedRunnable.wrap(command), initialDelaydelayunit);
    }
    @Override
    public ScheduledFuture<?> scheduleAtFixedRate(final Runnable commandfinal long initialDelayfinal long periodfinal TimeUnit unit) {
        return super.scheduleAtFixedRate(WrappedRunnable.wrap(command), initialDelayperiodunit);
    }
    @Override
    public <V> ScheduledFuture<V> schedule(final Callable<V> callablefinal long delayfinal TimeUnit unit) {
        return super.schedule(WrappedCallable.wrap(callable), delayunit);
    }
    @Override
    public ScheduledFuture<?> schedule(final Runnable commandfinal long delayfinal TimeUnit unit) {
        return super.schedule(WrappedRunnable.wrap(command), delayunit);
    }
New to GrepCode? Check out our FAQ X