下面列出了android.os.AsyncTask#THREAD_POOL_EXECUTOR 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Executes the calculation. Must be called after a {@link com.kimo.lib.alexei.Calculus} is set.
*
* @param callback to use when the calculation finish. The callback will be called in UI thread.
*/
public void showMe(Answer<T> callback) {
CalculusTask<T> task = new CalculusTask(image,calculus,callback);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if(executor == null) {
executor = AsyncTask.THREAD_POOL_EXECUTOR;
}
task.executeOnExecutor(executor);
} else {
task.execute();
}
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState, boolean ready) {
setContentView(R.layout.activity_contact_share_edit);
if (getIntent() == null) {
throw new IllegalStateException("You must supply extras to this activity. Please use the #getIntent() method.");
}
List<Uri> contactUris = getIntent().getParcelableArrayListExtra(KEY_CONTACT_URIS);
if (contactUris == null) {
throw new IllegalStateException("You must supply contact Uri's to this activity. Please use the #getIntent() method.");
}
View sendButton = findViewById(R.id.contact_share_edit_send);
sendButton.setOnClickListener(v -> onSendClicked(viewModel.getFinalizedContacts()));
RecyclerView contactList = findViewById(R.id.contact_share_edit_list);
contactList.setLayoutManager(new LinearLayoutManager(this));
contactList.getLayoutManager().setAutoMeasureEnabled(true);
ContactShareEditAdapter contactAdapter = new ContactShareEditAdapter(GlideApp.with(this), dynamicLanguage.getCurrentLocale(), this);
contactList.setAdapter(contactAdapter);
SharedContactRepository contactRepository = new SharedContactRepository(this,
AsyncTask.THREAD_POOL_EXECUTOR,
DatabaseFactory.getContactsDatabase(this));
viewModel = ViewModelProviders.of(this, new Factory(contactUris, contactRepository)).get(ContactShareEditViewModel.class);
viewModel.getContacts().observe(this, contacts -> {
contactAdapter.setContacts(contacts);
contactList.post(() -> contactList.scrollToPosition(0));
});
viewModel.getEvents().observe(this, this::presentEvent);
}
public static Executor getExecutor() {
synchronized (LOCK) {
if (AppliverySdk.executor == null) {
AppliverySdk.executor = AsyncTask.THREAD_POOL_EXECUTOR;
}
}
return AppliverySdk.executor;
}
/**
* Returns the Executor used by the SDK for non-AsyncTask background work.
*
* By default this uses AsyncTask Executor via reflection if the API level is high enough.
* Otherwise this creates a new Executor with defaults similar to those used in AsyncTask.
*
* @return an Executor used by the SDK. This will never be null.
*/
public static Executor getExecutor() {
synchronized (LOCK) {
if (FacebookSdk.executor == null) {
FacebookSdk.executor = AsyncTask.THREAD_POOL_EXECUTOR;
}
}
return FacebookSdk.executor;
}
public static Executor getExecutor() {
synchronized (LOCK) {
if (executor == null) {
executor = AsyncTask.THREAD_POOL_EXECUTOR;
}
}
return executor;
}
public KanboardAPI(String serverURL, final String username, final String password) throws IOException {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
});
kanboardURL = KanboardAPI.sanitizeURL(serverURL.trim());
Log.i(Constants.TAG, String.format("Host uses %s", kanboardURL.getProtocol()));
// threadPoolExecutor = new ThreadPoolExecutor(12, 12, 20, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(256));
threadPoolExecutor = (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR;
threadPoolExecutor.setCorePoolSize(12);
threadPoolExecutor.setMaximumPoolSize(12);
}
public Executor getCurrentExecutor() {
final DocumentInfo cwd = getCurrentDirectory();
if (cwd != null && cwd.authority != null) {
return ProviderExecutor.forAuthority(cwd.authority);
} else {
return AsyncTask.THREAD_POOL_EXECUTOR;
}
}
public Executor getCurrentExecutor() {
final DocumentInfo cwd = getCurrentDirectory();
if (cwd != null && cwd.authority != null) {
return ProviderExecutor.forAuthority(cwd.authority);
} else {
return AsyncTask.THREAD_POOL_EXECUTOR;
}
}
public Executor getCurrentExecutor() {
final DocumentInfo cwd = getCurrentDirectory();
if (cwd != null && cwd.authority != null) {
return ProviderExecutor.forAuthority(cwd.authority);
} else {
return AsyncTask.THREAD_POOL_EXECUTOR;
}
}
public KanboardAPI(String serverURL, final String username, final String password) throws IOException {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
});
kanboardURL = KanboardAPI.sanitizeURL(serverURL.trim());
Log.i(Constants.TAG, String.format("Host uses %s", kanboardURL.getProtocol()));
// threadPoolExecutor = new ThreadPoolExecutor(12, 12, 20, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(256));
threadPoolExecutor = (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR;
threadPoolExecutor.setCorePoolSize(12);
threadPoolExecutor.setMaximumPoolSize(12);
}
@TargetApi(11)
private static ThreadPoolExecutor getDefaultThreadPoolExecutor() {
try {
return (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR;
} catch (Throwable th) {
Log.e(TAG,
"Unexpected failure to get default ThreadPoolExecutor of AsyncTask.",
th);
return null;
}
}
public BiliWallpaperSource() {
super(NAME);
mClient = createDefaultClient();
mMainExecutor = new MainThreadExecutor();
mExecutor = AsyncTask.THREAD_POOL_EXECUTOR;
}
public void executeInPool(Params... values) {
super.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, values);
}
public AsyncStorageModule(ReactApplicationContext reactContext) {
this(reactContext, AsyncTask.THREAD_POOL_EXECUTOR);
}
public PoolSerialExecutor() {
this(AsyncTask.THREAD_POOL_EXECUTOR);
}
public AsyncTaskLoader(Context context) {
this(context, AsyncTask.THREAD_POOL_EXECUTOR);
}
public AsyncTaskLoader(Context context) {
this(context, AsyncTask.THREAD_POOL_EXECUTOR);
}
public AsyncTaskLoader(Context context) {
this(context, AsyncTask.THREAD_POOL_EXECUTOR);
}
public static Executor getExternalExecutor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && clientExecutor == null) {
return AsyncTask.THREAD_POOL_EXECUTOR;
}
return clientExecutor;
}
@SuppressLint("NewApi")
private static Executor getAsyncTaskThreadPool() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
? AsyncTask.THREAD_POOL_EXECUTOR
: null;
}