Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CountDownLatch冻结Android上的线程_Android_Kotlin_Retrofit2_Countdownlatch - Fatal编程技术网

CountDownLatch冻结Android上的线程

CountDownLatch冻结Android上的线程,android,kotlin,retrofit2,countdownlatch,Android,Kotlin,Retrofit2,Countdownlatch,我有一个方法,我想通过一个带有改造的API调用来检查我的令牌的有效性,我想等待结果。我本想使用CountDownLatch,但似乎CountDownLatch.await会锁定线程,但什么也没有发生,调试器无法到达onResponse部分。我和邮递员检查了我的API,调用实际上成功了 我还发现这个问题与我的问题相似,但没有帮助: 我是否使用了任何错误的东西,或者是否有其他方法可以获得所需的功能?改装文档中说: Callbacks are executed on the application'

我有一个方法,我想通过一个带有改造的API调用来检查我的令牌的有效性,我想等待结果。我本想使用CountDownLatch,但似乎CountDownLatch.await会锁定线程,但什么也没有发生,调试器无法到达onResponse部分。我和邮递员检查了我的API,调用实际上成功了

我还发现这个问题与我的问题相似,但没有帮助:

我是否使用了任何错误的东西,或者是否有其他方法可以获得所需的功能?

改装文档中说:

Callbacks are executed on the application's main (UI) thread.
主线程在方法CountDownLatchawait上被阻塞,因此将不执行CountDownLatchcountDown。您可以为回调指定一个后台执行器来运行,例如SingleThreadExecutor

Callbacks are executed on the application's main (UI) thread.
val retrofit = Retrofit.Builder()
        // options
        .callbackExecutor(Executors.newSingleThreadExecutor())
        // options
        .build()