Facebook SDK 卡在 AsyncTask 上,阻塞单个执行器上的所有线程

问题描述 投票:0回答:2

这是无限期地停留在可运行状态的 AsyncTask 的堆栈跟踪。

  at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) 
  at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:320) 
  at com.android.okhttp.Connection.upgradeToTls(Connection.java:1285)   
  at com.android.okhttp.Connection.connect(Connection.java:1197)    
  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:392)   
  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:295)   
  at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373) 
  at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323) 
  at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:491) 
  at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)   
  at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)    
  at com.facebook.Response.fromHttpConnection(Response.java:312)    
  at com.facebook.Request.executeConnectionAndWait(Request.java:1561)   
  at com.facebook.Request.executeBatchAndWait(Request.java:1460)    
  at com.facebook.Request.executeBatchAndWait(Request.java:1429)    
  at com.facebook.Request.executeBatchAndWait(Request.java:1411)    
  at com.facebook.Request.executeAndWait(Request.java:1383) 
  at com.facebook.Request.executeAndWait(Request.java:1269) 
  at com.facebook.internal.Utility.getAppSettingsQueryResponse(Utility.java:708)    
  at com.facebook.internal.Utility.access$000(Utility.java:57)  
  at com.facebook.internal.Utility$1.doInBackground(Utility.java:630)   
  at com.facebook.internal.Utility$1.doInBackground(Utility.java:627)   
  at android.os.AsyncTask$2.call(AsyncTask.java:288)    
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)   
  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)  
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)    
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)    
  at java.lang.Thread.run(Thread.java:818)  

为什么会这样?它阻止了我所有其他异步任务。请帮忙。

(Android API 22, FB SDK 3.21.1)
android facebook android-asynctask
2个回答
0
投票

但这不是解决方案。它看起来像是 FB 3.x.x SDK 版本中的错误。自从我将 SDK 更新到 4.x.x 后,我发现它不再重现了


0
投票

我遇到了类似的问题,在 Android 版本 9 之前,Facebook 在启动时会长时间占用 AsyncTask 线程池。我通过在应用程序构造函数中添加以下代码解决了这个问题:

FacebookSdk.setExecutor(new ThreadPoolExecutor(3, 3, 2000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()));

在 onCreate 中添加它已经太晚了,因为 Facebook 已经安排了任务。

© www.soinside.com 2019 - 2024. All rights reserved.