首页 \ 问答 \ 如何在Android上使用RxJava在多个线程上运行subsciber(How to run subsciber on multiple threads with RxJava on Android)

如何在Android上使用RxJava在多个线程上运行subsciber(How to run subsciber on multiple threads with RxJava on Android)

我是RxJava的新手并且在(我猜)简单的问题上苦苦挣扎。 我想在3个线程中处理订阅部分simuleasly。 这就是我使用FixedThreadPool的原因。 示例代码:

Observer.just("one", "two", "three", "four")
.observeOn(Schedulers.io())
.subscribeOn(Schedulers.from(Executors.newFixedThreadPool(3))
.subscribe(new Observer<String>() {

    public void onNext(String string) {
        Log.d(TAG, "Started: " + string);
        SystemClock.sleep(1000);
        Log.d(TAG, "Ended: " + string);
    }

    (...)

}

预期结果:

Started: one
Started: two
Started: three
Ended: one
Started: four
Ended: two
Ended: three
Ended: four

实际结果:

Started: one
Ended: one
Started: two
Ended: two
Started: three
Ended: three
Started: four
Ended: four

我究竟做错了什么?


I am new to RxJava and struggling on a (i guess) simple problem. I want to process the subscribe part simuleasly in 3 threads. Thats why I use a FixedThreadPool. Example code:

Observer.just("one", "two", "three", "four")
.observeOn(Schedulers.io())
.subscribeOn(Schedulers.from(Executors.newFixedThreadPool(3))
.subscribe(new Observer<String>() {

    public void onNext(String string) {
        Log.d(TAG, "Started: " + string);
        SystemClock.sleep(1000);
        Log.d(TAG, "Ended: " + string);
    }

    (...)

}

Expected result:

Started: one
Started: two
Started: three
Ended: one
Started: four
Ended: two
Ended: three
Ended: four

Actual result:

Started: one
Ended: one
Started: two
Ended: two
Started: three
Ended: three
Started: four
Ended: four

What am I doing wrong?


原文:https://stackoverflow.com/questions/33268120
更新时间:2023-07-27 10:07

最满意答案

这适用于双引号:

ghc -e ":script file.hs"

This works with double quotes:

ghc -e ":script file.hs"

相关问答

更多
  • TL; DR: $ ghc-pkg expose ghc 那么, runhaskell基本上是runhaskell的包装, runghc基本上是ghc 。 它们都遵循相同的规则:它们只能从配置的数据库中导入公开的包。 使用ghc-pkg describe {package-name} ,可以获得关于某个包的信息。 这里的重要领域是exposed : $ ghc-pkg describe ghc | grep expose exposed: False exposed-modules: 正如你所看到的,包 ...
  • 真的有点傻 GHC随附的每个图书馆均提供不少于4种口味的图书馆: 静态的 动态 异形 GHCI GHCi版本只是在一个.o文件中链接在一起的静态版本。 其他三个版本都有自己的接口文件集( .hi文件)。 分析版本似乎是未成功版本大小的两倍(这有点可疑,我应该研究一下)。 记住, GHC本身是一个图书馆 ,所以你得到4份GHC。 不仅如此,GHC二进制本身也是静态链接的,所以这是GHC的5个拷贝。 我们最近做了这样,GHCi可以使用静态.a文件。 这将使我们摆脱这些风味之一。 长期来说,我们应该动态地链接GH ...
  • 你几乎是对的, GHC_变量是来自自定义Setup.hs CPP定义: let buildinfo = emptyBuildInfo{ cppOptions = ["-DGHC_PATHS_GHC_PKG=" ++ show c_ghc_pkg, "-DGHC_PATHS_GHC=" ++ show c_ghc, "-DGHC_PATHS_LIBDIR=" ++ show libdir, ...
  • 你链接到的文档页面似乎有点鱼腥味。 您的GHC声称是7.4.1,似乎使用base-4.5.0.0 , GHC库文档和Hackage页面均显示base-4.5.0.0不包括GHC.TypeLits 。 这是完全合理的,因为与GHC 7.6.1不同,GHC 7.4.1 不支持类型文字 。 Something seems fishy with the documentation page you linked to. Your GHC claims to be 7.4.1, which does appear t ...
  • ghc是一个编译器,因此需要一个入口点来运行你的代码。 这是main功能,它应该具有类型IO ()并且存在于Main模块中(顶部没有module声明的module自动命名为Main )。 WinHugs是一个解释器 - 你可以用你喜欢的任何参数运行你喜欢的任何函数。 如果你想使用这样的ghc,你应该使用ghci - 它是ghc的解释器。 (WinHugs会更快地加载你的代码,而ghc会更快地运行你的代码。) ghc is a compiler, so needs a single entry point t ...
  • 这适用于双引号: ghc -e ":script file.hs" This works with double quotes: ghc -e ":script file.hs"
  • GHC使用/usr/lib/ghc/settings确定编译器和链接器选项,并使用/var/lib/ghc/package.conf.d/builtin_rts.conf等每个包文件来确定特定于包的链接器选项。 (自定义目录安装将分别在${GHC}/lib/ghc-${VERSION}/settings和${GHC}/lib/ghc-${VERSION}/package.conf.d 。) 以下是我为RTS找到的内容: ld-options: -u ghczmprim_GHCziTypes_Izh_stat ...
  • 如果在stack exec执行makefile,它将设置GHC_PACKAGE_PATH环境变量。 它还将适当地扩展PATH 。 或者,要在shell中设置此设置,您可以这样做 export GHC_PACKAGE_PATH=`stack path --ghc-package-path` If you execute the makefile within stack exec, it will set the GHC_PACKAGE_PATH environment variable. It will ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。