我有一个侦听外部事件的对象.收到事件后,我的对象需要执行任务(Runnable).但是,有一个限制:
一旦任务开始执行,我就不应该开始其他任务(我可以忽略它们),直到原始任务完成并且在那之后经过一定量的时间(限制).
这里建议使用信号量实现:
public class Sample {
private final Semaphore semaphore = new Semaphore(1);
private final ScheduledExecutorService executor;
public Sample(ScheduledExecutorService executor) {
this.executor = executor;
}
public void tryRun() {
if (semaphore.tryAcquire()) {
try {
executor.submit(
new Runnable() {
@Override
public void run() {
try {
doIt();
} finally {
try {
executor.schedule(
new Runnable() {
@Override
public void run() {
semaphore.release();
}
},
1,
TimeUnit.MINUTES
);
} catch (Throwable t) {
semaphore.release();
}
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个简单的代码,它使用以下命令定期执行一些任务:
Flux.interval(Duration.ZERO, interval, scheduler)
Run Code Online (Sandbox Code Playgroud)
有时(很少)我看到发出以下错误:
Could not emit tick 4218 due to lack of requests (interval doesn't support small downstream requests that replenish slower than the ticks)
Run Code Online (Sandbox Code Playgroud)
查看源代码我无法理解它是什么意思。有人可以解释一下吗?如果有人可以帮助我使用重现此问题的代码片段,那也会很棒。
谢谢
我正在尝试使用AbstractScheduledServicegoogle guava lib.在本课程的文档中,我看到以下内容:
此服务停止时,执行程序不会关闭.
我们为什么要在停止服务后让执行程序线程保持活动状态?这对我来说似乎是一个非常奇怪的建筑决策.我错过了什么?
我的项目中有几个GWT方面.它们被检测到,我可以在"项目结构"/"项目设置"/"构面"菜单中看到它们.但是,当我尝试为GWT设置"运行/调试配置"时,我在项目的下拉列表中看不到任何GWT模块.下拉列表已启用,但我看到的唯一值是"全部".尝试了几乎我能想到的一切,但没有运气.
有没有人见过这样的东西?任何帮助表示赞赏.
PS Intellij IDEA 11.0.2.