- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个Future
,我想知道它的状态。我想到的是这样的代码:
try {
// Is that a good idea? Counting on exceptions looks weird.
future.get(0, TimeUnit.MICROSECONDS);
this.status = DONE;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Throwables.propagate(e);
} catch (ExecutionException e) {
this.status = FAILED;
} catch (TimeoutException e) {
this.status = RUNNING;
} catch (CancellationException e) {
this.status = CANCELED;
}
看起来 FutureTask
会尝试持有锁,如果它能拿到锁,就会检查 Future
的状态。所以这似乎是个好主意。
这里有我遗漏的陷阱吗?
最佳答案
作为suggested in the comments , 只需使用 Future.isDone
检查运行状态。然而,您仍然需要调用 get()
来确定它是否成功完成,检查异常。
关于java - 通过 `Future` 检查 `get(0, TimeUnit.Microseconds)` 状态是个好主意吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14026513/
我希望以这样的方式对元素进行动画处理,使其每 1 微秒仅向下移动 1 像素,即 0.001 毫秒。 var microsec = 0.001 $("div").animate({top: "+=1px
我正在用 python 编写脚本,我需要知道我的代码中两点之间相隔了多少毫秒。 程序启动时我有一个全局变量是这样的: from datetime import datetime a=datetime.
我知道有毫秒 (Sleep(milli)) 但是我找不到一个用于微型.. 最佳答案 VS 11 开发预览包括处理线程的标准库部分。所以现在你可以说: std::this_thread::sleep_f
In [25]: datetime.fromtimestamp(15179052980380002/10000000) Out[25]: datetime.datetime(2018, 2, 6, 1
我在我的 centos 7 服务器中调用这个函数。 我发现std::this_thread::sleep_for(chrono::nanoseconds(1))实际上 sleep 了一毫秒,有什么解释
在 libc++ 中,std::chrono::microseconds 定义为 std::chrono::duration 对于 64 位平台,long long 定义导致了与 int64_t 的许
我需要在32位系统的android系统的linux内核中以微秒为单位获取64位的时间戳值 是否有直接的内核导出函数调用来实现它? 我看到 64 位的 jiffies,并且有将 64 位的 jiffie
我想使用 Perl 和/或 Python 来实现以下 JavaScript 伪代码: var c=0; function timedCount() { c=c+1; print("c=" +
我正在使用 unsigned long 来收集性能数据,同时按如下方式分析应用程序 unsigned long time_taken = (unsigned long) ((finish_time_i
我是第一次接触ApacheIoTDB,注意到时间序列时间戳的默认单位是毫秒。我想知道能不能改成纳秒或其他……我怎样才能做到这一点呢?。文件本应包括它,但我还没有找到它。
我是第一次接触ApacheIoTDB,注意到时间序列时间戳的默认单位是毫秒。我想知道能不能改成纳秒或其他……我怎样才能做到这一点呢?。文件本应包括它,但我还没有找到它。
我有一个Future,我想知道它的状态。我想到的是这样的代码: try { // Is that a good idea? Counting on exceptions looks weird
刚刚在我的 Windows (8) 工作站和 AIX 上测试了这段代码: public static void main(String[] args) { System.out
我目前正在努力处理一段非常简单的代码,它表明 ARM GCC 的 1 级优化器以某种方式破坏了一个简单的公式。 这使用标准编译器设置 (O1) 在最新的 Atmel 6.2 Studio 上运行。 A
更新:Timestamp 的构造函数的“秒的分数”参数实际上需要纳秒……我猜是百分之一秒,我的低值被四舍五入了。留题引用.... 我正在努力使用 Oracle 的 C++ 库 - OCCI。总结: 创
我们在 BigQuery 中使用带有标准 SQL 的简单选择查询。 select expiration_date FROM cards 但是,它返回以下错误, 错误:无法返回相对于 Unix 纪元的无
我在从 MySQL 5.7 表中检索 datetime(6) 字段时遇到问题。如果我直接从 mysql 客户端运行它,它可以工作: mysql> SELECT arrival from table1
我是一名优秀的程序员,十分优秀!