Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 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.mogwee.executors;
 
 
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 = Logger.getLogger();

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

Parameters:
name thread name base
 
     public FailsafeScheduledExecutor(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(int corePoolSizeString name)
     {
         super(corePoolSizenew NamedThreadFactory(name));
     }
 
     @Override
     public <T> Future<T> submit(Callable<T> task)
     {
         return super.submit(WrappedCallable.wrap(task));
     }
 
     @Override
     public <T> Future<T> submit(Runnable task, 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(Runnable task)
     {
         return super.submit(WrappedRunnable.wrap(task));
     }
 
     @Override
     public void execute(Runnable command)
     {
         super.execute(WrappedRunnable.wrap(command));
     }
 
     @Override
     public ScheduledFuture<?> scheduleWithFixedDelay(Runnable commandlong initialDelaylong delayTimeUnit unit)
     {
         return super.scheduleWithFixedDelay(WrappedRunnable.wrap(command), initialDelaydelayunit);
     }
 
     @Override
     public ScheduledFuture<?> scheduleAtFixedRate(Runnable commandlong initialDelaylong periodTimeUnit unit)
     {
         return super.scheduleAtFixedRate(WrappedRunnable.wrap(command), initialDelayperiodunit);
     }
 
     @Override
     public <V> ScheduledFuture<V> schedule(Callable<V> callablelong delayTimeUnit unit)
     {
         return super.schedule(WrappedCallable.wrap(callable), delayunit);
     }
 
    @Override
    public ScheduledFuture<?> schedule(Runnable commandlong delayTimeUnit unit)
    {
        return super.schedule(WrappedRunnable.wrap(command), delayunit);
    }
New to GrepCode? Check out our FAQ X