当前位置: 首页>>代码示例>>Java>>正文


Java FutureTask.get方法代码示例

本文整理汇总了Java中java.util.concurrent.FutureTask.get方法的典型用法代码示例。如果您正苦于以下问题:Java FutureTask.get方法的具体用法?Java FutureTask.get怎么用?Java FutureTask.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.FutureTask的用法示例。


在下文中一共展示了FutureTask.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkAndMarkRunningHbck

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
 * This method maintains a lock using a file. If the creation fails we return null
 *
 * @return FSDataOutputStream object corresponding to the newly opened lock file
 * @throws IOException
 */
private FSDataOutputStream checkAndMarkRunningHbck() throws IOException {
  RetryCounter retryCounter = lockFileRetryCounterFactory.create();
  FileLockCallable callable = new FileLockCallable(retryCounter);
  ExecutorService executor = Executors.newFixedThreadPool(1);
  FutureTask<FSDataOutputStream> futureTask = new FutureTask<FSDataOutputStream>(callable);
  executor.execute(futureTask);
  final int timeoutInSeconds = getConf().getInt(
    "hbase.hbck.lockfile.maxwaittime", DEFAULT_WAIT_FOR_LOCK_TIMEOUT);
  FSDataOutputStream stream = null;
  try {
    stream = futureTask.get(timeoutInSeconds, TimeUnit.SECONDS);
  } catch (ExecutionException ee) {
    LOG.warn("Encountered exception when opening lock file", ee);
  } catch (InterruptedException ie) {
    LOG.warn("Interrupted when opening lock file", ie);
    Thread.currentThread().interrupt();
  } catch (TimeoutException exception) {
    // took too long to obtain lock
    LOG.warn("Took more than " + timeoutInSeconds + " seconds in obtaining lock");
    futureTask.cancel(true);
  } finally {
    executor.shutdownNow();
  }
  return stream;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:32,代码来源:HBaseFsck.java

示例2: onActivityResult

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
 * deal with the system camera's shot.
 */
public boolean onActivityResult(final int requestCode, final int resultCode) {
    if (requestCode != REQ_CODE_CAMERA) {
        return false;
    }
    if (resultCode != Activity.RESULT_OK) {
        callbackError();
        return false;
    }
    FutureTask<Boolean> task = BoxingExecutor.getInstance().runWorker(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return rotateImage(resultCode);
        }
    });
    try {
        if (task != null && task.get()) {
            callbackFinish();
        } else {
            callbackError();
        }
    } catch (InterruptedException | ExecutionException ignore) {
        callbackError();
    }
    return true;
}
 
开发者ID:Bilibili,项目名称:boxing,代码行数:29,代码来源:CameraPickerHelper.java

示例3: readText

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
public String readText(ExecutorService executorService, long timeout)
        throws IOException, InterruptedException, ExecutionException,
        TimeoutException {
    FutureTask<String> futureTask = new FutureTask(this);
    executorService.execute(futureTask);

    String text = futureTask.get(timeout, TimeUnit.MILLISECONDS);

    return text;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:11,代码来源:HttpFuture.java

示例4: waitForCompletion

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
private void waitForCompletion() throws InterruptedException, ExecutionException {
    for (FutureTask<Void> t : tasks) {
        t.get();
    }
    if (tasks.isEmpty()) {
        throw new RuntimeException("No classes found, or specified.");
    }
    System.out.println("Parsed " + tasks.size() + " classfiles");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:CallerSensitiveFinder.java

示例5: getValue

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
public JsonArray getValue() throws InterruptedException,ExecutionException{
    if (Platform.isFxApplicationThread()) {
        return getValueBase();
    }else{
        final FutureTask<JsonArray> task = new FutureTask<>(this::getValueBase);
        Platform.runLater(task);
        return task.get();
    }
}
 
开发者ID:whitewoodcity,项目名称:xbrowser,代码行数:10,代码来源:TableView.java

示例6: evaluateCall

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
final Object evaluateCall(final Object fn, final Object p) throws InterruptedException, ExecutionException {
    FutureTask<?> t = new FutureTask<Object>(new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            JSObject jsRegFn = (JSObject) fn;
            return jsRegFn.call("call", null, p);
        }
    });
    ctx.execute(t);
    return t.get();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:AbstractWizard.java

示例7: evaluateProp

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
final Object evaluateProp(final String prop) throws InterruptedException, ExecutionException {
    FutureTask<?> t = new FutureTask<Object>(new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            return getPropertyValue(data, prop);
        }
    });
    ctx.execute(t);
    return t.get();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:AbstractWizard.java

示例8: main

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
public static void main(String[] args) throws ExecutionException, InterruptedException {
    //1执行 Callable 方式 需要 FutureTask 实现类的支持 用于接收运算结果。
    ThreadDemo td = new ThreadDemo();
    FutureTask<Integer> result = new FutureTask<Integer>(td);
    new Thread(result).start();
    //2 接收线程运算后的结果
    Integer sum = result.get();//FutureTask 也可以用于闭锁
    System.out.println(sum);
    System.out.println("--------------------");
}
 
开发者ID:ZhangJin1988,项目名称:juc,代码行数:11,代码来源:TestCallable.java

示例9: widthProperty

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
public DoubleProperty widthProperty()throws InterruptedException,ExecutionException{
    if (Platform.isFxApplicationThread()) {
        return body.widthProperty();
    }

    counter++;
    if(counter>maxCounter){
        throw new ExecutionException(new Exception(hint));
    }

    final FutureTask<DoubleProperty> task = new FutureTask<>(() -> body.widthProperty());
    Platform.runLater(task);
    return task.get();

}
 
开发者ID:whitewoodcity,项目名称:xbrowser,代码行数:16,代码来源:Canvas.java

示例10: getWidth

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
public double getWidth() throws InterruptedException,ExecutionException{
    if (Platform.isFxApplicationThread()) {
        return getWidthBase();
    }

    counter++;
    if(counter>maxCounter){
        throw new ExecutionException(new Exception(hint));
    }

    final FutureTask<Double> task = new FutureTask<>(() -> getWidthBase());
    Platform.runLater(task);
    return task.get();
}
 
开发者ID:whitewoodcity,项目名称:xbrowser,代码行数:15,代码来源:Canvas.java

示例11: compress

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
 * @param imageCompressor see {@link ImageCompressor}.
 * @param maxSize the proximate max size for compression
 * @return may be a little bigger than expected for performance.
 */
public static boolean compress(final ImageCompressor imageCompressor, final ImageMedia image, final long maxSize) {
    if (imageCompressor == null || image == null || maxSize <= 0) {
        return false;
    }
    FutureTask<Boolean> task = BoxingExecutor.getInstance().runWorker(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            final String path = image.getPath();
            File compressSaveFile = imageCompressor.getCompressOutFile(path);
            File needCompressFile = new File(path);
            if (BoxingFileHelper.isFileValid(compressSaveFile)) {
                image.setCompressPath(compressSaveFile.getAbsolutePath());
                return true;
            }
            if (!BoxingFileHelper.isFileValid(needCompressFile)) {
                return false;
            } else if (image.getSize() < maxSize) {
                image.setCompressPath(path);
                return true;
            } else {
                try {
                    File result = imageCompressor.compress(needCompressFile, maxSize);
                    boolean suc = BoxingFileHelper.isFileValid(result);
                    image.setCompressPath(suc ? result.getAbsolutePath() : null);
                    return suc;
                } catch (IOException | OutOfMemoryError | NullPointerException | IllegalArgumentException e) {
                    image.setCompressPath(null);
                    BoxingLog.d("image compress fail!");
                }
            }
            return false;
        }
    });
    try {
        return task != null && task.get();
    } catch (InterruptedException | ExecutionException ignore) {
        return false;
    }
}
 
开发者ID:Bilibili,项目名称:boxing,代码行数:45,代码来源:CompressTask.java

示例12: startCamera

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
/**
 * start system camera to take a picture
 *
 * @param activity      not null if fragment is null.
 * @param fragment      not null if activity is null.
 * @param subFolderPath a folder in external DCIM,must start with "/".
 */
public void startCamera(final Activity activity, final Fragment fragment, final String subFolderPath) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !takePhotoSecure(activity, fragment, subFolderPath)) {
        FutureTask<Boolean> task = BoxingExecutor.getInstance().runWorker(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                try {
                    // try...try...try
                    Camera camera = Camera.open();
                    camera.release();
                } catch (Exception e) {
                    BoxingLog.d("camera is not available.");
                    return false;
                }
                return true;
            }
        });
        try {
            if (task != null && task.get()) {
                startCameraIntent(activity, fragment, subFolderPath, MediaStore.ACTION_IMAGE_CAPTURE, REQ_CODE_CAMERA);
            } else {
                callbackError();
            }
        } catch (InterruptedException | ExecutionException ignore) {
            callbackError();
        }

    }
}
 
开发者ID:Bilibili,项目名称:boxing,代码行数:36,代码来源:CameraPickerHelper.java

示例13: waitAllTaskComplete

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
private void waitAllTaskComplete(SparseArray<FutureTask<?>> uploadTaskMap) throws ExecutionException,
        InterruptedException {
    for (int i = 0; i < uploadTaskMap.size(); i++) {
        FutureTask<?> uploadTask = uploadTaskMap.valueAt(i);
        try {
            // just need block here
            Objects result = (Objects) uploadTask.get();
            Logger.i("get index:" + i + " result>>>>>>" + result);
        } catch (InterruptedException | ExecutionException e) { // executorService shut down
            throw e;
        }
    }
}
 
开发者ID:zkwlx,项目名称:DroidTelescope,代码行数:14,代码来源:ExecutorManager.java

示例14: onDismatch

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
@Override
public boolean onDismatch(final LogProcessContext logCtx, Content leftContent) {
	final AfterTransCallRegisterContent afterTransCallContent = (AfterTransCallRegisterContent) leftContent;
	final EasyTransRequest<?,?> params = afterTransCallContent.getParams();
	final BusinessIdentifer businessIdentifer = ReflectUtil.getBusinessIdentifer(params.getClass());
	
	if(logCtx.getFinalMasterTransStatus() == null){
		LOG.info("final trans status unknown,process later." + logCtx.getLogCollection());
		return false;
	}else if(logCtx.getFinalMasterTransStatus()){
		//commit
		//execute the register method
		FutureTask<Object> futureTask = new FutureTask<Object>(new Callable<Object>() {
			@Override
			public Object call() throws Exception {
				return rpcClient.call(businessIdentifer.appId(), businessIdentifer.busCode(), afterTransCallContent.getCallSeq(), AFTER_TRANS_METHOD_NAME, afterTransCallContent.getParams(),logCtx);
			}
		});
		
		futureTask.run();//get result in this thread
		try {
			futureTask.get();
			FutureProxy<?> object = (FutureProxy<?>) logCtx.getExtendResourceMap().get(getFutureKey(afterTransCallContent));
			if(object != null){
				object.setResult(futureTask);
			}
		} catch (InterruptedException | ExecutionException e) {
			LOG.error("After transaction method execute ERROR",e);
			return false;//try later
		}
		
		AfterTransCalledContent compensatedContent = new AfterTransCalledContent();
		compensatedContent.setLeftDemiConentId(leftContent.getcId());
		logCtx.getLogCache().cacheLog(compensatedContent);
		LOG.info("After transaction method executed:" + businessIdentifer);
		return true;
	}else{
		//roll back
		//do nothing
		return true;
	}
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:43,代码来源:AfterTransMethodExecutor.java

示例15: getY

import java.util.concurrent.FutureTask; //导入方法依赖的package包/类
public double getY() throws InterruptedException,ExecutionException{
    if(Platform.isFxApplicationThread()) return body.getLayoutY();
    final FutureTask<Double> task = new FutureTask<>(()->body.getLayoutY());
    Platform.runLater(task);
    return task.get();
}
 
开发者ID:whitewoodcity,项目名称:xbrowser,代码行数:7,代码来源:Chart.java


注:本文中的java.util.concurrent.FutureTask.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。