List of usage examples for java.lang Thread MIN_PRIORITY
int MIN_PRIORITY
To view the source code for java.lang Thread MIN_PRIORITY.
Click Source Link
From source file:im.neon.util.VectorUtils.java
/** * Set the user avatar in an imageView.//from w w w . j ava2s .com * * @param context the context * @param session the session * @param imageView the image view * @param avatarUrl the avatar url * @param userId the user id * @param displayName the user display name */ public static void loadUserAvatar(final Context context, final MXSession session, final ImageView imageView, final String avatarUrl, final String userId, final String displayName) { // sanity check if ((null == session) || (null == imageView) || !session.isAlive()) { return; } // reset the imageView tag imageView.setTag(null); if (session.getMediasCache().isAvatarThumbnailCached(avatarUrl, context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size))) { session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(), imageView, avatarUrl, context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size)); } else { if (null == mImagesThread) { mImagesThread = new HandlerThread("ImagesThread", Thread.MIN_PRIORITY); mImagesThread.start(); mImagesThreadHandler = new android.os.Handler(mImagesThread.getLooper()); mUIHandler = new Handler(Looper.getMainLooper()); } final Bitmap bitmap = VectorUtils.getAvatar(imageView.getContext(), VectorUtils.getAvatarColor(userId), TextUtils.isEmpty(displayName) ? userId : displayName, false); // test if the default avatar has been computed if (null != bitmap) { imageView.setImageBitmap(bitmap); final String tag = avatarUrl + userId + displayName; imageView.setTag(tag); if (!MXMediasCache.isMediaUrlUnreachable(avatarUrl)) { mImagesThreadHandler.post(new Runnable() { @Override public void run() { if (TextUtils.equals(tag, (String) imageView.getTag())) { session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(), imageView, avatarUrl, context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size), bitmap); } } }); } } else { final String tmpTag0 = "00" + avatarUrl + "-" + userId + "--" + displayName; imageView.setTag(tmpTag0); // create the default avatar in the background thread mImagesThreadHandler.post(new Runnable() { @Override public void run() { if (TextUtils.equals(tmpTag0, (String) imageView.getTag())) { imageView.setTag(null); setDefaultMemberAvatar(imageView, userId, displayName); if (!MXMediasCache.isMediaUrlUnreachable(avatarUrl)) { final String tmpTag1 = "11" + avatarUrl + "-" + userId + "--" + displayName; imageView.setTag(tmpTag1); // wait that it is rendered to load the right one mUIHandler.post(new Runnable() { @Override public void run() { // test if the imageView tag has not been updated if (TextUtils.equals(tmpTag1, (String) imageView.getTag())) { final String tmptag2 = "22" + avatarUrl + userId + displayName; imageView.setTag(tmptag2); mImagesThreadHandler.post(new Runnable() { @Override public void run() { // test if the imageView tag has not been updated if (TextUtils.equals(tmptag2, (String) imageView.getTag())) { final Bitmap bitmap = VectorUtils.getAvatar( imageView.getContext(), VectorUtils.getAvatarColor(userId), TextUtils.isEmpty(displayName) ? userId : displayName, false); session.getMediasCache().loadAvatarThumbnail( session.getHomeserverConfig(), imageView, avatarUrl, context.getResources().getDimensionPixelSize( R.dimen.profile_avatar_size), bitmap); } } }); } } }); } } } }); } } }
From source file:org.muse.mneme.impl.SubmissionCacheImpl.java
/** * Start the expiration thread.// ww w. jav a 2 s. com */ protected void start() { m_threadStop = false; m_thread = new Thread(this, getClass().getName()); m_thread.setDaemon(true); m_thread.setPriority(Thread.MIN_PRIORITY + 2); m_thread.start(); }
From source file:tvbrowser.extras.reminderplugin.ReminderSettingsTab.java
/** * Called by the host-application, if the user wants to save the settings. *//*from w w w . j a v a 2s. c om*/ public void saveSettings() { mSettings.setProperty("soundfile", mSoundFileChB.getTextField().getText()); mSettings.setProperty("execfile", mExecFileStr); mSettings.setProperty("execparam", mExecParamStr); mSettings.setProperty("usemsgbox", String.valueOf(mReminderWindowChB.isSelected())); mSettings.setProperty("usesound", String.valueOf(mSoundFileChB.isSelected())); mSettings.setProperty("usebeep", String.valueOf(mBeep.isSelected())); mSettings.setProperty("useexec", String.valueOf(mExecChB.isSelected())); ReminderPlugin.getInstance().setClientPluginsTargets(mClientPluginTargets); mSettings.setProperty("autoCloseBehaviour", mCloseOnEnd.isSelected() ? "onEnd" : mCloseNever.isSelected() ? "never" : "onTime"); mSettings.setProperty("autoCloseReminderTime", mAutoCloseReminderTimeSp.getValue().toString()); mSettings.setProperty("defaultReminderEntry", Integer.toString(mDefaultReminderEntryList.getSelectedIndex())); mSettings.setProperty("showTimeSelectionDialog", String.valueOf(mShowTimeSelectionDlg.isSelected())); mSettings.setProperty("showRemovedDialog", String.valueOf(mShowRemovedDlg.isSelected())); mSettings.setProperty("showTimeCounter", String.valueOf(!mCloseNever.isSelected() && mShowTimeCounter.isSelected())); mSettings.setProperty("alwaysOnTop", String.valueOf(mShowAlwaysOnTop.isSelected())); ReminderPlugin.getInstance().setMarkPriority(mMarkingsPanel.getSelectedPriority()); Thread saveThread = new Thread("Save reminders") { public void run() { ReminderPlugin.getInstance().store(); } }; saveThread.setPriority(Thread.MIN_PRIORITY); saveThread.start(); }
From source file:org.apparatus_templi.Coordinator.java
private static void startDrivers() { // this should never be called when drivers are currently running assert loadedDrivers.isEmpty() : "list of loaded drivers was not empty when starting drivers"; assert driverThreads.isEmpty() : "list of driver threads was not empty when starting drivers"; // Instantiate all drivers specified in the config file String driverList = prefs.getPreference(Prefs.Keys.driverList); assert driverList != null : "driver list should not be null"; if (driverList == null || driverList.equals("")) { Log.w(TAG, "No drivers were specified in the configuration " + "file: '" + prefs.getPreference(Prefs.Keys.configFile) + "', nothing will be loaded"); } else {//from w w w . j av a2s . c om Log.c(TAG, "Initializing drivers..."); String[] drivers = driverList.split(","); for (String driverClassName : drivers) { try { Class<?> c = Class.forName("org.apparatus_templi.driver." + driverClassName); Driver d = (Driver) c.newInstance(); loadDriver(d); } catch (Exception e) { Log.d(TAG, "unable to load driver '" + driverClassName + "'"); } } } // Start the driver threads for (String driverName : loadedDrivers.keySet()) { Log.c(TAG, "Starting driver " + driverName); Thread t = new Thread(loadedDrivers.get(driverName)); t.setPriority(Thread.MIN_PRIORITY); driverThreads.put(loadedDrivers.get(driverName), t); t.start(); } }
From source file:au.com.redboxresearchdata.fascinator.plugins.JsonHarvestQueueConsumer.java
public void setPriority(int newPriority) { if (newPriority >= Thread.MIN_PRIORITY && newPriority <= Thread.MAX_PRIORITY) { thread.setPriority(newPriority); }/*from w w w .j av a2 s .co m*/ }
From source file:im.neon.contacts.ContactsManager.java
/** * List the local contacts./* w w w .j a v a2s. com*/ */ public void refreshLocalContactsSnapshot() { boolean isPopulating; synchronized (LOG_TAG) { isPopulating = mIsPopulating; } // test if there is a population is in progress if (isPopulating) { return; } synchronized (LOG_TAG) { mIsPopulating = true; } // refresh the contacts list in background Thread t = new Thread(new Runnable() { public void run() { long t0 = System.currentTimeMillis(); ContentResolver cr = mContext.getContentResolver(); HashMap<String, Contact> dict = new HashMap<>(); // test if the user allows to access to the contact if (isContactBookAccessAllowed()) { // get the names Cursor namesCur = null; try { namesCur = cr.query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Contacts.DISPLAY_NAME_PRIMARY, ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID, ContactsContract.Contacts.PHOTO_THUMBNAIL_URI }, ContactsContract.Data.MIMETYPE + " = ?", new String[] { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE }, null); } catch (Exception e) { Log.e(LOG_TAG, "## refreshLocalContactsSnapshot(): Exception - Contact names query Msg=" + e.getMessage()); } if (namesCur != null) { try { while (namesCur.moveToNext()) { String displayName = namesCur.getString( namesCur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY)); String contactId = namesCur.getString(namesCur.getColumnIndex( ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID)); String thumbnailUri = namesCur.getString(namesCur.getColumnIndex( ContactsContract.CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI)); if (null != contactId) { Contact contact = dict.get(contactId); if (null == contact) { contact = new Contact(contactId); dict.put(contactId, contact); } if (null != displayName) { contact.setDisplayName(displayName); } if (null != thumbnailUri) { contact.setThumbnailUri(thumbnailUri); } } } } catch (Exception e) { Log.e(LOG_TAG, "## refreshLocalContactsSnapshot(): Exception - Contact names query2 Msg=" + e.getMessage()); } namesCur.close(); } // get the phonenumbers Cursor phonesCur = null; try { phonesCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER, ContactsContract.CommonDataKinds.Phone.CONTACT_ID }, null, null, null); } catch (Exception e) { Log.e(LOG_TAG, "## refreshLocalContactsSnapshot(): Exception - Phone numbers query Msg=" + e.getMessage()); } if (null != phonesCur) { try { while (phonesCur.moveToNext()) { final String pn = phonesCur.getString( phonesCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); final String pnE164 = phonesCur.getString(phonesCur .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER)); if (!TextUtils.isEmpty(pn)) { String contactId = phonesCur.getString(phonesCur .getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID)); if (null != contactId) { Contact contact = dict.get(contactId); if (null == contact) { contact = new Contact(contactId); dict.put(contactId, contact); } contact.addPhoneNumber(pn, pnE164); } } } } catch (Exception e) { Log.e(LOG_TAG, "## refreshLocalContactsSnapshot(): Exception - Phone numbers query2 Msg=" + e.getMessage()); } phonesCur.close(); } // get the emails Cursor emailsCur = null; try { emailsCur = cr .query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, new String[] { ContactsContract.CommonDataKinds.Email.DATA, // actual email ContactsContract.CommonDataKinds.Email.CONTACT_ID }, null, null, null); } catch (Exception e) { Log.e(LOG_TAG, "## refreshLocalContactsSnapshot(): Exception - Emails query Msg=" + e.getMessage()); } if (emailsCur != null) { try { while (emailsCur.moveToNext()) { String email = emailsCur.getString( emailsCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)); if (!TextUtils.isEmpty(email)) { String contactId = emailsCur.getString(emailsCur .getColumnIndex(ContactsContract.CommonDataKinds.Email.CONTACT_ID)); if (null != contactId) { Contact contact = dict.get(contactId); if (null == contact) { contact = new Contact(contactId); dict.put(contactId, contact); } contact.addEmailAdress(email); } } } } catch (Exception e) { Log.e(LOG_TAG, "## refreshLocalContactsSnapshot(): Exception - Emails query2 Msg=" + e.getMessage()); } emailsCur.close(); } } synchronized (LOG_TAG) { mContactsList = new ArrayList<>(dict.values()); mIsPopulating = false; } if (0 != mContactsList.size()) { long delta = System.currentTimeMillis() - t0; VectorApp.sendGAStats(VectorApp.getInstance(), VectorApp.GOOGLE_ANALYTICS_STATS_CATEGORY, VectorApp.GOOGLE_ANALYTICS_STARTUP_CONTACTS_ACTION, mContactsList.size() + " contacts in " + delta + " ms", delta); } // define the PIDs listener PIDsRetriever.getInstance().setPIDsRetrieverListener(mPIDsRetrieverListener); // trigger a PIDs retrieval // add a network listener to ensure that the PIDS will be retreived asap a valid network will be found. MXSession defaultSession = Matrix.getInstance(VectorApp.getInstance()).getDefaultSession(); if (null != defaultSession) { defaultSession.getNetworkConnectivityReceiver().addEventListener(mNetworkConnectivityReceiver); // reset the PIDs retriever statuses mIsRetrievingPids = false; mArePidsRetrieved = false; // the PIDs retrieval is done on demand. } if (null != mListeners) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { for (ContactsManagerListener listener : mListeners) { try { listener.onRefresh(); } catch (Exception e) { Log.e(LOG_TAG, "refreshLocalContactsSnapshot : onRefresh failed" + e.getMessage()); } } } }); } } }); t.setPriority(Thread.MIN_PRIORITY); t.start(); }
From source file:es.udc.gii.common.eaf.algorithm.parallel.evaluation.DistributedEvaluation.java
protected void master(EvolutionaryAlgorithm algorithm, List<Individual> individuals, List<ObjectiveFunction> functions, List<Constraint> constraints) { /* Initialize the global state. */ this.functions = functions; this.constraints = constraints; this.popSize = individuals.size(); this.individualsToEvaluate = individuals; this.firtstInd = 0; this.evaluatedIndividuals = 0; if (this.barrier == null) { this.barrier = new CyclicBarrier(2); }/*from w w w .ja v a 2 s .c o m*/ boolean setChunkSizeToCero = false; if (getChunkSize() == 0) { setChunkSizeToCero = true; int size = individuals.size(); int tSize = getTopology().getSize(); if (size < tSize) { setChunkSize(1); } else { setChunkSize(size / tSize); } } notifyObservers(CURRENT_EVALUATION_STARTED, this); /* Initialize the communication thread. */ if (communicationThread == null) { communicationThread = new Thread(new CommunicationThread(), "CommThread"); communicationThread.setPriority(Thread.MAX_PRIORITY); Thread.currentThread().setPriority(Thread.MIN_PRIORITY); commThreadMustWait = true; communicationThread.start(); } else { synchronized (this.communicationThread) { commThreadMustWait = false; this.communicationThread.notify(); } } /* Run the evaluation thread (current thread, no especial thread is created) */ evaluationThread(algorithm); if (setChunkSizeToCero) { setChunkSize(0); } notifyObservers(CURRENT_EVALUATION_ENDED, this); setState(CURRENT_EVALUATION_NOT_STARTED); }
From source file:nl.privacybarometer.privacyvandaag.service.FetcherService.java
private int refreshFeeds(final long keepDateBorderTime) { ContentResolver cr = getContentResolver(); final Cursor cursor = cr.query(FeedColumns.CONTENT_URI, FeedColumns.PROJECTION_ID, null, null, null); int nbFeed = (cursor != null) ? cursor.getCount() : 0; ExecutorService executor = Executors.newFixedThreadPool(THREAD_NUMBER, new ThreadFactory() { @Override/* w w w . ja va 2 s .co m*/ public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setPriority(Thread.MIN_PRIORITY); return t; } }); CompletionService<Integer> completionService = new ExecutorCompletionService<>(executor); while (cursor != null && cursor.moveToNext()) { final String feedId = cursor.getString(0); completionService.submit(new Callable<Integer>() { @Override public Integer call() { int result = 0; try { result = refreshFeed(feedId, keepDateBorderTime); } catch (Exception e) { Log.e(TAG, "Error refreshing feed " + e.getMessage()); } return result; } }); } if (cursor != null) cursor.close(); int globalResult = 0; for (int i = 0; i < nbFeed; i++) { try { Future<Integer> f = completionService.take(); // ModPrivacyVandaag: the count of new articles after a feed is refreshed globalResult += f.get(); } catch (Exception e) { Log.e(TAG, "Error counting new articles " + e.getMessage()); } } executor.shutdownNow(); // To purge all threads return globalResult; // ModPrivacyVandaag: As far as I can see: this contains the number of new articles from a refresh of the feeds. }
From source file:com.juick.android.MessagesFragment.java
private void init(final boolean moveToTop) { if (implicitlyCreated) return;/*from w w w . jav a2s. co m*/ parent.imagePreviewHelper = listAdapter.imagePreviewHelper = new ImagePreviewHelper( (ViewGroup) getView().findViewById(R.id.imagepreview_container), parent); final MessageListBackingData savedMainList = JuickAdvancedApplication.instance.getSavedList(getActivity()); final ListView lv = getListView(); boolean canUseMainList = getActivity() instanceof MainActivity; // if (savedMainList != null && canUseMainList) { messagesSource = savedMainList.messagesSource; initListWithMessages(savedMainList.messages); int selectItem = 0; ListAdapter wrappedAdapter = lv.getAdapter(); for (int i = 0; i < wrappedAdapter.getCount(); i++) { Object ai = wrappedAdapter.getItem(i); if (ai != null && ai instanceof JuickMessage) { if (((JuickMessage) ai).getMID().equals(savedMainList.topMessageId)) { selectItem = i; } } } lv.setSelectionFromTop(selectItem, savedMainList.topMessageScrollPos); JuickAdvancedApplication.instance.setSavedList(null, false); } else { final MessagesLoadNotification messagesLoadNotification = new MessagesLoadNotification(getActivity(), handler); Thread thr = new Thread("Download messages (init)") { public void run() { final MessagesLoadNotification notification = messagesLoadNotification; final Utils.Function<Void, RetainedData> then = new Utils.Function<Void, RetainedData>() { @Override public Void apply(final RetainedData mespos) { handler.post(new Runnable() { @Override public void run() { notification.statusText.setText("Filter and format.."); } }); Log.w("com.juick.advanced", "getFirst: before filter"); final ArrayList<JuickMessage> messages = filterMessages(mespos.messages); Log.w("com.juick.advanced", "getFirst: after filter"); Boolean ownView = null; if (!JuickMessagesAdapter.dontKeepParsed(parent)) { for (JuickMessage juickMessage : messages) { if (ownView == null) { MicroBlog blog = MainActivity.microBlogs .get(juickMessage.getMID().getMicroBlogCode()); ownView = blog instanceof OwnRenderItems; } if (!ownView) { juickMessage.parsedText = JuickMessagesAdapter.formatMessageText(parent, juickMessage, false); } } } final Parcelable listPosition = mespos.viewState; if (isAdded()) { if (messages.size() == 0) { handler.post(new Runnable() { @Override public void run() { if (notification.lastError == null) { notification.statusText .setText(parent.getString(R.string.EmptyList)); } else { notification.statusText.setText( "Error obtaining messages: " + notification.lastError); } notification.progressBar.setVisibility(View.GONE); } }); } final Activity activity = getActivity(); if (activity != null) { final Parcelable finalListPosition = listPosition; activity.runOnUiThread(new Runnable() { public void run() { try { if (isAdded()) { lastPrepareMessages(messages, new Runnable() { @Override public void run() { if (!hasListView()) { handler.postDelayed(this, 300); return; } initListWithMessages(messages); if (moveToTop) { lv.setSelection(0); } else { if (finalListPosition != null) { lv.onRestoreInstanceState(finalListPosition); } else { //setSelection(messagesSource.supportsBackwardRefresh() ? 1 : 0); setSelection(0); } } Log.w("com.juick.advanced", "getFirst: end."); handler.postDelayed(new Runnable() { @Override public void run() { onListLoaded(); } }, 10); } }); } } catch (IllegalStateException e) { Toast.makeText(activity, e.toString(), Toast.LENGTH_LONG).show(); } } }); } } else { Log.w("com.juick.advanced", "getFirst: not added!"); } return null; } }; if (getActivity() != null) messagesSource.setContext(getActivity()); if (restoreData == null) { messagesSource.getFirst(notification, new Utils.Function<Void, ArrayList<JuickMessage>>() { @Override public Void apply(ArrayList<JuickMessage> juickMessages) { return then.apply(new RetainedData(juickMessages, null)); } }); } else { then.apply((RetainedData) restoreData); restoreData = null; } } }; thr.setPriority(Thread.MIN_PRIORITY); thr.start(); } }
From source file:org.opencms.search.CmsSearchIndex.java
/** * Adds a parameter.<p>//from w w w .j a va2s . c om * * @param key the key/name of the parameter * @param value the value of the parameter */ public void addConfigurationParameter(String key, String value) { if (PERMISSIONS.equals(key)) { m_checkPermissions = Boolean.valueOf(value).booleanValue(); } else if (TIME_RANGE.equals(key)) { m_checkTimeRange = Boolean.valueOf(value).booleanValue(); } else if (EXCERPT.equals(key)) { m_createExcerpt = Boolean.valueOf(value).booleanValue(); } else if (EXTRACT_CONTENT.equals(key)) { m_extractContent = Boolean.valueOf(value).booleanValue(); } else if (BACKUP_REINDEXING.equals(key)) { m_backupReindexing = Boolean.valueOf(value).booleanValue(); } else if (MAX_HITS.equals(key)) { try { m_maxHits = Integer.parseInt(value); } catch (NumberFormatException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_PARAM_3, value, key, getName())); } if (m_maxHits < (MAX_HITS_DEFAULT / 100)) { m_maxHits = MAX_HITS_DEFAULT; LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_PARAM_3, value, key, getName())); } } else if (PRIORITY.equals(key)) { m_priority = Integer.parseInt(value); if (m_priority < Thread.MIN_PRIORITY) { m_priority = Thread.MIN_PRIORITY; LOG.error(Messages.get().getBundle().key(Messages.LOG_SEARCH_PRIORITY_TOO_LOW_2, value, new Integer(Thread.MIN_PRIORITY))); } else if (m_priority > Thread.MAX_PRIORITY) { m_priority = Thread.MAX_PRIORITY; LOG.debug(Messages.get().getBundle().key(Messages.LOG_SEARCH_PRIORITY_TOO_HIGH_2, value, new Integer(Thread.MAX_PRIORITY))); } } else if (LUCENE_MAX_MERGE_DOCS.equals(key)) { try { m_luceneMaxMergeDocs = Integer.valueOf(value); } catch (NumberFormatException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_PARAM_3, value, key, getName())); } } else if (LUCENE_MERGE_FACTOR.equals(key)) { try { m_luceneMergeFactor = Integer.valueOf(value); } catch (NumberFormatException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_PARAM_3, value, key, getName())); } } else if (LUCENE_RAM_BUFFER_SIZE_MB.equals(key)) { try { m_luceneRAMBufferSizeMB = Double.valueOf(value); } catch (NumberFormatException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_PARAM_3, value, key, getName())); } } else if (LUCENE_USE_COMPOUND_FILE.equals(key)) { m_luceneUseCompoundFile = Boolean.valueOf(value); } }