Is rxJava library compatible with Google Appengine? If so are there any limitations? The only info I have found is mention of \'partial support\' on grepcode. http://grep
You should create a child of RxJavaSchedulersHook and override its methods using your scheduler which use com.google.appengine.api.ThreadManager
:
I've done it like this :
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);
}
}
Then you should register this hook. Better to do this in an ServletContextListener implementation:
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.
}
}
It works for me.
The problem is the limitation of Java Threads in Google Appengine: https://developers.google.com/appengine/docs/java/#Java_The_sandbox
RxJava uses Java Thread
and Executor
in the Scheduler
implementations. So the codes which get involved some concurrent Scheduler
s can not run in Google Java Sandbox.
If you want to use Scheduler
in Google Appengine, you need to implement a special Scheduler
by yourself. Besides, some operators may use Scheduler
by default, such as delay
use Schedulers.computation()
by default. Remember to use their Scheduler
overload methods.