CodingPuppy
V2EX  ›  问与答

学习使用 Rxjava 有一个小问题求教

  •  
  •   CodingPuppy · Aug 13, 2016 · 1387 views
    This topic created in 3569 days ago, the information mentioned may be changed or developed.
    val start = System.currentTimeMillis()
    updateMonitor.testRxjavaThread()//sleep 10s
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe { text -> helloText?.text = text }
    val end = System.currentTimeMillis()
     Log.d("test", "cost time :" + (end - start))
    

    虽然使用了.subscribeOn(Schedulers.io())但是 第一次调用, cost time 输出竟然是 2 秒多,之后再调用就没有时间消耗了。

    这是什么原因?什么东西初始化这么慢?普遍现象么?

    Supplement 1  ·  Aug 13, 2016
    2S 是使用 retrofit + rxjava 是的时间。
    如果工作仅是 sleep 10s ,这里 log 时间是 30-60ms ,第一次调用后再次调用就是 1ms
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1407 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 23:57 · PVG 07:57 · LAX 16:57 · JFK 19:57
    ♥ Do have faith in what you're doing.