- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码基本上遵循官方教程,主要目的是收集一个订阅(Constants.UNFINISHEDSUBID)中的所有消息并在另一个订阅上重新发布它们。但目前我面临着一个我无法解决的问题。在我的实现中,调用subscriber.stopAsync() 会导致以下异常:
Mai 04, 2017 4:59:25 PM com.google.common.util.concurrent.AbstractFuture executeListener
SCHWERWIEGEND: RuntimeException while executing runnable com.google.common.util.concurrent.Futures$6@6e13e898 with executor java.util.concurrent.Executors$DelegatedScheduledExecutorService@2f3c6ac4
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@60d40af2 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@d55b6e[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 320]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:326)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:533)
at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:622)
at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:668)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:817)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:753)
at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:613)
at io.grpc.stub.ClientCalls$GrpcFuture.set(ClientCalls.java:458)
at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:437)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:428)
at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:76)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:514)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:431)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:546)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:152)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我还注意到这种随机的情况,有时是所有消息,有时只是少数或没有一条消息被收集。调用subscriber.stopAsync()不是正确的方法吗?
我当前的实现:
protected void pullUnfinished() throws Exception {
List<PubsubMessage> jobsToRepublish = new ArrayList<>();
SubscriptionName subscription =
SubscriptionName.create(Constants.PROJECTID, Constants.UNFINISHEDSUBID);
MessageReceiver receiver = new MessageReceiver() {
@Override
public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
synchronized(jobsToRepublish){
jobsToRepublish.add(message);
}
String unfinishedJob = message.getData().toStringUtf8();
LOG.info("got message: {}", unfinishedJob);
consumer.ack();
}
};
Subscriber subscriber = null;
try {
ChannelProvider channelProvider = new PlainTextChannelProvider();
subscriber = Subscriber.defaultBuilder(subscription, receiver)
.setChannelProvider(channelProvider)
.build();
subscriber.addListener(new Subscriber.Listener() {
@Override
public void failed(Subscriber.State from, Throwable failure) {
System.err.println(failure);
}
}, MoreExecutors.directExecutor());
subscriber.startAsync().awaitRunning();
Thread.sleep(60000);
} finally {
if (subscriber != null) {
subscriber.stopAsync(); //Causes the exception
}
}
publishJobs(jobsToRepublish);
}
public class PlainTextChannelProvider implements ChannelProvider {
@Override
public boolean shouldAutoClose() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean needsExecutor() {
// TODO Auto-generated method stub
return false;
}
@Override
public ManagedChannel getChannel() throws IOException {
return NettyChannelBuilder.forAddress("localhost", 8085)
.negotiationType(NegotiationType.PLAINTEXT)
.build();
}
@Override
public ManagedChannel getChannel(Executor executor) throws IOException {
return getChannel();
}
}
最佳答案
当我从 JUnit 测试运行类似代码时遇到了完全相同的问题,并发现了这个 related answer一般而言,在多线程上,表明线程池已关闭,而监听器仍在引用它。我还查看了 Subscriber.java 的代码在 GitHub 上,在 JavaDoc 中关于 startAsync() 找到了一个接收大量消息的示例,建议等待 stopAsync() 终止。
尝试改变
subscriber.stopAsync();
至
subscriber.stopAsync().awaitTerminated();
为我工作。
关于java - Subscriber.stopAsync() 导致 RejectedExecutionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43786716/
我正在使用 Swift Joint,但不明白两者之间的区别 func subscribe(_ subscriber: S) where S : Subscriber, Self.Failure ==
大多数 Flowable.subscribe() 重载返回一个 Disposable ,它可以清理流。我习惯于这样做: Disposable d = Flowable.just() .map(
我正在尝试测试主题 symbol$ 的输出存在于我的组件上。 具体来说,当组件属性 symbol 时,主题符号 $ 应该发出(这是正确的词吗?)已经改变。 但是,我找不到测试输出到 symbol$ 的
Observable.just(10,20,30,40,50) .subscribe { Consumer{ Log.d(TAG, "Where
我在 subscribe 中有带有 subscribe 的代码: this.http.post('/update1', newData).subscribe( (response) => {
我有两个页面/模板, 仪表板(还包含一些用户特定数据)。 用户。 我正在使用带有 Blaze 模板的 Meteor 1.5。登陆页面是仪表板。我在两个模板中都使用集合 Users 的通用订阅。 场景
我刚接触 Angular2 一周! 基本上有 2 个 API 调用。 第一个 API 调用为我提供了一个 json 对象数组 (queryResults)。 (第一次订阅) 在 View 中显示该数组
我已经在 stackoverflow 上尝试了很多关于修复此错误的提议,但现在我只需要问一下,因为我已经花了很多时间,现在一无所获。 我有这个简单的服务: constructor(private ht
给定一个配置有任务执行器的发布-订阅 channel ,如果抛出异常,是否可以中断其有序订阅者的调用? 例如,在此示例中,“已工作”消息仍然由序列中的第二个服务激活器发送。我希望这种事不要发生。
我正在尝试使用 Intent to PDF 应用程序下载和发送 pdf 以显示此处显示的文件 answer of JDenais这是下载 pdf 并通过 Intent 传递它的代码。 public c
我目前正在调查 RxJS's .merge但是我也会在这里问这个问题,因为我发现这里的解释有时非常精彩。 好的,我有一个根据用户输入打开模态窗口的表单,我订阅模态关闭事件并传回一些我将在调用/订阅服务
我刚刚对我的 Angular 6 应用程序进行了 ng 升级,现在我得到: ERROR in node_modules/@angular/flex-layout/core/typings/observ
如果您有一个事件驱动的架构并且订阅事件的服务在继续创建链中的下一个事件之前必须等待多个事件(相同类型),那么最佳实践是什么? 一个例子是图书订单处理服务,它必须等待订单中的每一本书都被仓库处理,然后再
我使用下面的代码进行异步调用,我想知道在 getData() 函数中生成的 data 的值,但是,我得到 undefined 因为调用还没有解决。有什么办法可以解决吗? getData(address
我在订阅我的 HTML 页面中的下拉值更改时遇到实现 knockout Js 的问题。这是我的 HTML Request Types :
函数定义 resetComponent(){ console.log("1st"); ... this.background = { }; this.uploadMode = fals
在我的代码中,我正在使用 @Subscribe 注释来监听事件: @Subscribe public void orderUpdate(OrderUpdateEvent event) 我的问题是,对于
我正在使用 Angular2 和 NodeJS 编写 API,我正在为我的 ِAPI 实现服务,该 API 应该获取任务列表并显示它。这是任务服务: import {Injectable} from
我正在尝试使用来自服务器的 json 响应创建动态菜单,但出现此错误: MenuComponent.html:4 ERROR TypeError: Cannot read property 'subs
我查看了许多资源,包括 this , this和 this ,但我一直无法达到预期的效果。 我要做的就是验证用户(使用 firebase),然后在验证后加载他们的配置文件并将其存储在变量 userPr
我是一名优秀的程序员,十分优秀!