trying to improved classloader dead lock

This commit is contained in:
Mariotaku Lee 2017-05-09 10:58:10 +08:00
parent 476c714489
commit 3cbef0b1bf
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
2 changed files with 43 additions and 1 deletions

View File

@ -0,0 +1,27 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.ktextension
import android.os.Looper
/**
* Created by mariotaku on 2017/5/9.
*/
val Looper.isCurrentThreadCompat: Boolean get() = Thread.currentThread() == thread

View File

@ -28,15 +28,19 @@ import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.net.ConnectivityManager
import android.os.AsyncTask
import android.os.Looper
import android.support.multidex.MultiDex
import com.bumptech.glide.Glide
import nl.komponents.kovenant.android.startKovenant
import nl.komponents.kovenant.android.stopKovenant
import nl.komponents.kovenant.task
import okhttp3.Dns
import org.apache.commons.lang3.concurrent.ConcurrentUtils
import org.mariotaku.commons.logansquare.LoganSquareMapperFinder
import org.mariotaku.kpreferences.KPreferences
import org.mariotaku.kpreferences.get
import org.mariotaku.kpreferences.set
import org.mariotaku.ktextension.isCurrentThreadCompat
import org.mariotaku.ktextension.setLayoutDirectionCompat
import org.mariotaku.mediaviewer.library.MediaDownloader
import org.mariotaku.restfu.http.RestHttpClient
@ -64,6 +68,9 @@ import org.mariotaku.twidere.util.refresh.AutoRefreshController
import org.mariotaku.twidere.util.sync.DataSyncProvider
import org.mariotaku.twidere.util.sync.SyncController
import java.util.*
import java.util.concurrent.Callable
import java.util.concurrent.Executors
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@ -311,7 +318,15 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis
Class.forName(AsyncTask::class.java.name)
} catch (ignore: ClassNotFoundException) {
}
val executor = Executors.newSingleThreadExecutor()
LoganSquareMapperFinder.setDefaultExecutor(object : LoganSquareMapperFinder.FutureExecutor {
override fun <T> submit(callable: Callable<T>): Future<T> {
if (Looper.getMainLooper().isCurrentThreadCompat) {
return ConcurrentUtils.constantFuture(callable.call())
}
return executor.submit(callable)
}
})
}
companion object {