List of usage examples for java.util.concurrent FutureTask FutureTask
public FutureTask(Callable<V> callable)
From source file:org.apache.hadoop.hbase.regionserver.HRegion.java
private void doProcessRowWithTimeout(final RowProcessor<?, ?> processor, final long now, final HRegion region, final List<KeyValue> mutations, final WALEdit walEdit, final long timeout) throws IOException { // Short circuit the no time bound case. if (timeout < 0) { try {/*from ww w . java2 s.c o m*/ processor.process(now, region, mutations, walEdit); } catch (IOException e) { LOG.warn("RowProcessor:" + processor.getClass().getName() + " throws Exception on row(s):" + Bytes.toStringBinary(processor.getRowsToLock().iterator().next()) + "...", e); throw e; } return; } // Case with time bound FutureTask<Void> task = new FutureTask<Void>(new Callable<Void>() { @Override public Void call() throws IOException { try { processor.process(now, region, mutations, walEdit); return null; } catch (IOException e) { LOG.warn("RowProcessor:" + processor.getClass().getName() + " throws Exception on row(s):" + Bytes.toStringBinary(processor.getRowsToLock().iterator().next()) + "...", e); throw e; } } }); rowProcessorExecutor.execute(task); try { task.get(timeout, TimeUnit.MILLISECONDS); } catch (TimeoutException te) { LOG.error("RowProcessor timeout:" + timeout + " ms on row(s):" + Bytes.toStringBinary(processor.getRowsToLock().iterator().next()) + "..."); throw new IOException(te); } catch (Exception e) { throw new IOException(e); } }