@Override public void run() { Process.setThreadPriority(THREAD_PRIORITY_BACKGROUND); super.run(); } }
@Override public void run() { try { Process.setThreadPriority(mThreadPriority); } catch (Throwable t) { } runnable.run(); } };
@Override public void run() { try { Process.setThreadPriority(mThreadPriority); } catch (Throwable ignored) { } runnable.run(); } };
@Override public void run() { if (Looper.myLooper() == null) { Looper.prepare(); } try { Process.setThreadPriority(mThreadPriority); } catch (SecurityException e) { /** * From {@link Process#THREAD_PRIORITY_DISPLAY}, some applications can not change the * thread priority to that of the main thread. This catches that potential error and * tries to set a lower priority. */ Process.setThreadPriority(mThreadPriority + 1); } r.run(); } };
@Override public void execute(@NonNull Runnable r) { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); r.run(); } }
@Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); String[] args={String.valueOf(position), prose}; getWritableDatabase().execSQL("INSERT OR REPLACE INTO notes (position, prose) VALUES (?, ?)", args); } }
@Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); String[] args={String.valueOf(position)}; Cursor c= getReadableDatabase().rawQuery("SELECT prose FROM notes WHERE position = ? ", args); if (c.getCount() > 0) { c.moveToFirst(); EventBus.getDefault().post(new NoteLoadedEvent(position, c.getString(0))); } c.close(); } }
/** * Try to raise the priority of {@param threadId} to {@param targetThreadPriority}. * * @return the original thread priority of the target thread. */ public static int tryRaiseThreadPriority(int threadId, int targetThreadPriority) { // Main thread is about to be blocked, raise the running thread priority. final int originalThreadPriority = Process.getThreadPriority(threadId); boolean success = false; while (!success && targetThreadPriority < originalThreadPriority) { // Keep trying to increase thread priority of running thread as long as it is an increase. try { Process.setThreadPriority(threadId, targetThreadPriority); success = true; } catch (SecurityException e) { /* From {@link Process#THREAD_PRIORITY_DISPLAY}, some applications can not change the thread priority to that of the main thread. This catches that potential error and tries to set a lower priority. */ targetThreadPriority += Process.THREAD_PRIORITY_LESS_FAVORABLE; } } return originalThreadPriority; } }
@Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); Gson gson=new Gson(); try { InputStream is=assets.open("book/contents.json"); BufferedReader reader= new BufferedReader(new InputStreamReader(is)); contents.set(gson.fromJson(reader, BookContents.class)); EventBus.getDefault().post(new BookLoadedEvent(getBook())); } catch (IOException e) { Log.e(getClass().getSimpleName(), "Exception parsing JSON", e); } } }
@Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
@Override public void run() { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND); PresoRoster.getInstance().load(ctxt); EventBus.getDefault().postSticky(new RosterLoadedEvent()); } }
@Override public void run() { try { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO); int bytesRecord; byte[] tempBuffer = new byte[bufferSize]; mRecorder.startRecording(); while (isStart) { if (mRecorder != null) { bytesRecord = mRecorder.read(tempBuffer, 0, bufferSize); if (bytesRecord == AudioRecord.ERROR_INVALID_OPERATION || bytesRecord == AudioRecord.ERROR_BAD_VALUE) { continue; } if (bytesRecord != 0 && bytesRecord != -1) { dos.write(tempBuffer, 0, bytesRecord); } else { break; } } } } catch (Exception e) { e.printStackTrace(); } }
@Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST); for (Photo photo : photos) { if (isCancelled) { return; } FutureTarget<File> futureTarget = GlideApp.with(context) .downloadOnly() .load(photo) .submit(Api.SQUARE_THUMB_SIZE, Api.SQUARE_THUMB_SIZE); try { futureTarget.get(); } catch (InterruptedException e) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Interrupted waiting for background downloadOnly", e); } } catch (ExecutionException e) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Got ExecutionException waiting for background downloadOnly", e); } } GlideApp.with(context).clear(futureTarget); } } }
@Override public void run() { // why PMD suppression is needed: https://github.com/pmd/pmd/issues/808 android.os.Process.setThreadPriority(DEFAULT_PRIORITY); //NOPMD AccessorMethodGeneration if (preventNetworkOperations) { StrictMode.setThreadPolicy( new ThreadPolicy.Builder() .detectNetwork() .penaltyDeath() .build()); } try { super.run(); } catch (Throwable t) { uncaughtThrowableStrategy.handle(t); } } };
private void runInBackground() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); while (!stopped) { String commandDescription = null;
@Test public void getThreadPriority_currentThread_returnsCurrentThreadPriority() { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO); assertThat(android.os.Process.getThreadPriority(/*tid=*/ 0)) .isEqualTo(android.os.Process.THREAD_PRIORITY_AUDIO); }
@Test public void getThreadPriority_returnsThreadPriority() { android.os.Process.setThreadPriority(123, android.os.Process.THREAD_PRIORITY_VIDEO); assertThat(android.os.Process.getThreadPriority(123)) .isEqualTo(android.os.Process.THREAD_PRIORITY_VIDEO); }
Process.setThreadPriority(runningThreadId, originalThreadPriority); } catch (IllegalArgumentException | SecurityException ignored) { } finally {
@Test public void setThreadPriorityOneArgument_setsCurrentThreadPriority() { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO); assertThat(android.os.Process.getThreadPriority(android.os.Process.myTid())) .isEqualTo(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO); } }
@Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);