List of usage examples for android.os Process setThreadPriority
public static final native void setThreadPriority(int priority) throws IllegalArgumentException, SecurityException;
From source file:com.grazerss.EntryManager.java
private void runSimpleJob(final String name, final Runnable runnable, final Handler handler) { new Thread(new Runnable() { public void run() { try { runJob(new Job(name, EntryManager.this) { @Override/*www.j a va 2s . c om*/ public void run() throws Exception { try { Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST); synchronized (this) { if (isModelCurrentlyUpdated()) { return; } lockModel(name); } runnable.run(); } finally { synchronized (this) { unlockModel(name); } } } }); } catch (final Throwable e) { if (handler != null) { handler.post(new Runnable() { public void run() { showExceptionToast(name, e); } }); } } } }).start(); }
From source file:com.grazerss.EntryManager.java
private void switchStorageProvider() { Log.d(TAG, "Switch Storage Provider"); if (isModelCurrentlyUpdated()) { return;//from w ww . j av a 2s . c o m } final String newPrefValue = getSharedPreferences().getString(SETTINGS_STORAGE_PROVIDER_KEY, null); final String oldStorageProviderClass = fileContextAdapter.getClass().getName(); final String newStorageProviderClass = STORAGE_PROVIDER_SD_CARD.equals(newPrefValue) ? SdCardStorageAdapter.class.getName() : PhoneMemoryStorageAdapter.class.getName(); if (!oldStorageProviderClass.equals(newStorageProviderClass)) { runningThread = new Thread(new Runnable() { public void run() { final PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); Log.i(TAG, "Wake lock acquired at " + new Date().toString() + "."); wl.acquire(); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); final Timing t = new Timing("Storage Provider Switch", ctx); ModelUpdateResult result = null; if (isModelCurrentlyUpdated()) { return; } try { lockModel("EM.switchStorageProvider.run"); } catch (final IllegalStateException ise) { return; } try { Log.i(TAG, "Switching storage providers started at " + new Date().toString() + "."); fireModelUpdateStarted("Switching storage providers", false, true); Log.d(TAG, "Change of storage provider detected."); final List<Job> jobList = new LinkedList<Job>(); final Job clearOldStorageProvider = new Job("Clearing Old Storage Provider", EntryManager.this) { @Override public void run() { Log.d(TAG, "Clearing the old storage provider."); doClearCache(); if (fileContextAdapter.canWrite()) { WebPageDownloadDirector.removeAllAssets(fileContextAdapter, ctx); } } }; jobList.add(clearOldStorageProvider); final Job switchStorageProviders = new Job("Switching Storage Providers", EntryManager.this) { @Override public void run() throws Exception { Log.d(TAG, "Establishing new storage provider: " + newStorageProviderClass); fileContextAdapter = newStorageProviderClass.equals( SdCardStorageAdapter.class.getName()) ? new SdCardStorageAdapter(ctx) : new PhoneMemoryStorageAdapter(ctx); Log.d(TAG, "New storage provider established."); } }; jobList.add(switchStorageProviders); final Job clearNewStorageProvider = new Job("Clearing New Storage Provider", EntryManager.this) { @Override public void run() { Log.d(TAG, "Clearing the new storage provider."); doClearCache(); if (fileContextAdapter.canWrite()) { WebPageDownloadDirector.removeAllAssets(fileContextAdapter, ctx); } } }; jobList.add(clearNewStorageProvider); runJobs(jobList); result = new SwitchStorageProviderResult(); } catch (final Throwable throwable) { result = new SwitchStorageProviderFailed(throwable); Log.d(TAG, "Problem during switching storage providers.", throwable); t.stop(); } finally { unlockModel("EM.switchStorageProvider.run"); clearCancelState(); fireModelUpdateFinished(result); fireStatusUpdated(); Log.i(TAG, "Switching storage providers finished at " + new Date().toString() + "."); wl.release(); t.stop(); } } }, "Storage Provider Switch Worker"); runningThread.start(); } }
From source file:com.newsrob.EntryManager.java
public void doUnsubscribeFeed(String feedAtomId) { try {/*from w w w . j ava 2 s. c o m*/ Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST); synchronized (this) { if (isModelCurrentlyUpdated()) return; lockModel("EM.requestUnsubscribeFeed"); } if (canFeedBeUnsubscribed(feedAtomId)) { databaseHelper.addFeed2Unsubscribe(feedAtomId); DBQuery dbq = prepareMarkFeedReadQuery(feedAtomId); if (dbq != null) doMarkAllRead(dbq); } } finally { synchronized (this) { unlockModel("EM.requestUnsubscribeFeed"); } } }