rxJava库是否与Google Appengine兼容?如果是,有哪些限制?我发现的唯一信息是grepcode上提到的“部分支持”。 http://grepcode.com/snapshot/repo1.maven.org/maven2/com.netflix.rxjava/rxjava-core/0.9.0
什么不被支持?
com.google.appengine.api.ThreadManager
。我是这样做的:public class MyThreadSchedulersHook extends RxJavaSchedulersHook {
private final Executor executor = new ScheduledThreadPoolExecutor(10, ThreadManager.backgroundThreadFactory());
@Override
public Scheduler getComputationScheduler() {
return Schedulers.from(executor);
}
@Override
public Scheduler getIOScheduler() {
return Schedulers.from(executor);
}
@Override
public Scheduler getNewThreadScheduler() {
return Schedulers.from(executor);
}
}
接下来你需要注册这个钩子。最好在ServletContextListener实现中完成:
public class ContextListener implements ServletContextListener {
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
RxJavaPlugins.getInstance().registerSchedulersHook(new RxMainThreadSchedulersHook());
}
@Override
public void contextDestroyed(final ServletContextEvent servletContextEvent) {
// App Engine does not currently invoke this method.
}
}
对我来说有效。
MyThreadSchedulersHook
和RxMainThreadSchedulersHook
是同一个类,你只是在更新此帖子时将其重命名了。 - ZakTaccardiRxJavaPlugins.getInstance()
已经被弃用,你应该使用 RxJavaSchedulersHook / _RxJavaHooks_,例如RxJavaSchedulersHook.createNewThreadScheduler(ThreadManager.currentRequestThreadFactory())
,它将返回一个Scheduler
,你可以将其传递给RxJavaHooks.onNewThreadScheduler(Scheduler)
。 - VallaDanger