6
有时当我调试我的应用程序时,我遇到了RxCachedThreadScheduler-1中的InterruptedException。这里的痕迹: 在Android上进行调试时RxJava缓存线程中的InterruptedException
Fatal Exception: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:1991)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2025)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1048)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:776)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1035)
我有我订阅我观察到这样的自定义视图:
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
sub = FollowHandler.getInstance().getObservable()
.filter(new Func1<FollowEvent, Boolean>() {
@Override
public Boolean call(FollowEvent followEvent) {
if(followEvent == null || followEvent.user == null
|| user == null)
return false;
return followEvent.user.id == user.id;
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<FollowEvent>() {
@Override
public void onCompleted() {}
@Override
public void onError(Throwable e) {}
@Override
public void onNext(FollowEvent followEvent) {
reactToThisNiceEvent(followEvent);
}
});
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if(sub != null)
sub.unsubscribe();
}
这里的观察到:
其中eventSubject.asObservable()
.observeOn(Schedulers.io())
.doOnNext(new Action1<FollowEvent>() {
@Override
public void call(FollowEvent followEvent) {
if(followEvent != null)
doSomethingNice(followEvent);
}
})
.share();
eventSubject是简单的PublishSubject。 我使用RxAndroid 1.1.0和RxJava 1.1.0。
有谁知道为什么会发生这种情况?
感谢您的回答。我会尝试按照你的建议去做subscribeOn和observeOn。然而,我可能需要一段时间来测试它。 关于分享,我确实需要它。因为共享之前的任务必须在所有订户之间共享(并且所有订户的结果都相同)。如果我删除共享,则将为所有订户调用doOnNext(这是毫无意义的)。 并感谢更正isUnsubscribed()检查。我完全错过了。 – Avsector