List of usage examples for java.lang Thread setPriority
public final void setPriority(int newPriority)
From source file:ECallCenter21.java
synchronized void moveVMUsageMeter(final int toParam, boolean smoothParam) { if ((smoothParam) && (!moveVMUSageMeterIsLocked)) { moveVMUSageMeterIsLocked = true; Thread moveVMUsageMeterThread = new Thread(allThreadsGroup, new Runnable() { @Override/*from www . ja v a 2s. c o m*/ @SuppressWarnings("empty-statement") public void run() { if (performanceMeter != null) { double from = performanceMeter.getVMUsageNeedle().doubleValue(); double counter = from; double to = toParam; if (from < to) { for (counter = from; counter < to; counter++) { performanceMeter.setVMUsageNeedle(counter); try { Thread.sleep(5); } catch (InterruptedException ex) { } } } else { for (counter = from; counter > to; counter--) { performanceMeter.setVMUsageNeedle(counter); try { Thread.sleep(5); } catch (InterruptedException ex) { } } } } moveVMUSageMeterIsLocked = false; } }); moveVMUsageMeterThread.setName("moveVMUsageMeterThread"); moveVMUsageMeterThread.setDaemon(runThreadsAsDaemons); moveVMUsageMeterThread.setPriority(5); moveVMUsageMeterThread.start(); } else { if (performanceMeter != null) { performanceMeter.setVMUsageNeedle(toParam); } } }
From source file:ECallCenter21.java
/** * * @param toParam/*from ww w. j av a 2s.c om*/ * @param smoothParam */ synchronized protected void movePerformanceMeter(final double toParam, boolean smoothParam) { if ((smoothParam) && (!performanceMeterIsLocked)) { performanceMeterIsLocked = true; Thread movePerformanceMeterThread = new Thread(allThreadsGroup, new Runnable() { @Override @SuppressWarnings("empty-statement") public void run() { if (performanceMeter != null) { double from = performanceMeter.getCallPerHourNeedle().doubleValue(); double counter = from; double to = toParam; if (from < to) { for (counter = from; counter < to; counter += 1) { performanceMeter.setCallPerHourNeedle(counter); try { Thread.sleep(3); } catch (InterruptedException ex) { } } } else { for (counter = from; counter > to; counter -= 1) { performanceMeter.setCallPerHourNeedle(counter); try { Thread.sleep(3); } catch (InterruptedException ex) { } } } } performanceMeterIsLocked = false; } }); movePerformanceMeterThread.setName("movePerformanceMeterThread"); movePerformanceMeterThread.setDaemon(runThreadsAsDaemons); movePerformanceMeterThread.setPriority(5); movePerformanceMeterThread.start(); } else { if (performanceMeter != null) { performanceMeter.setCallPerHourNeedle(toParam); } } }
From source file:im.neon.contacts.ContactsManager.java
/** * List the local contacts.// www . j a v a2 s .c om */ 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:ECallCenter21.java
synchronized void moveCallSpeedSlider(final int toParam, boolean smoothParam) // When going faster, this routine does not move to "toParam" but instead to a little less than current slider value { if ((smoothParam) && (!moveCallSpeedSliderIsLocked)) { moveCallSpeedSliderIsLocked = true; Thread moveCallSpeedSliderThread = new Thread(allThreadsGroup, new Runnable() { @Override/*from ww w . j av a2 s . c o m*/ @SuppressWarnings("empty-statement") public void run() { if (callSpeedSlider != null) { int from = callSpeedSlider.getValue(); int counter = from; int to = toParam; int step = Math.round((callSpeedSlider.getMaximum() - callSpeedSlider.getMinimum()) / 100); int get = (callSpeedSlider.getValue() - callSpeedSlider.getMinimum()); int max = (callSpeedSlider.getMaximum() - callSpeedSlider.getMinimum()); int perdecimal = (get / (max / 10)) + 2; if (from < to) // Sliding down to longer intervals { for (counter = from; counter < to; counter += step) { callSpeedSlider.setValue(counter); try { Thread.sleep(5); } catch (InterruptedException ex) { } } } else { // for (counter = from; counter > (from - (step * 5)); counter -= step ) { callSpeedSlider.setValue(counter); try { Thread.sleep(100); } catch (InterruptedException ex) { } } for (counter = from; counter > (from - (step * perdecimal)); counter -= step) { callSpeedSlider.setValue(counter); try { Thread.sleep(100); } catch (InterruptedException ex) { } } } } moveCallSpeedSliderIsLocked = false; } }); moveCallSpeedSliderThread.setName("moveCallSpeedSliderThread"); moveCallSpeedSliderThread.setDaemon(runThreadsAsDaemons); moveCallSpeedSliderThread.setPriority(5); moveCallSpeedSliderThread.start(); } else { if (callSpeedSlider != null) { callSpeedSlider.setValue(toParam); } } }
From source file:ECallCenter21.java
/** * * @param callCenterModeParam//from ww w. j av a2s. co m * @param managedModeParam * @param campaignIdParam * @throws SQLException * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws Exception */ public ECallCenter21(final String callCenterModeParam, final boolean managedModeParam, final int campaignIdParam) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, Exception { this(); while (!defaultConstructorIsReady) { try { Thread.sleep(100); } catch (InterruptedException ex) { } } Thread outboundCampaignThread = new Thread(allThreadsGroup, new Runnable() { @Override public void run() { callCenterIsNetManaged = managedModeParam; if (callCenterModeParam.equals("Outbound")) { positionWindow("Left"); callCenterIsOutBound = true; try { Thread.sleep(mediumMessagePeriod); } catch (InterruptedException ex) { } autoPowerOff = true; setPowerOn(true); while ((getCallCenterStatus() != POWEREDON) && (getCallCenterStatus() != RUNNING) && (getCallCenterStatus() != PAUSING) && (getCallCenterStatus() != RERUNBREAK)) { try { Thread.sleep(100); } catch (InterruptedException ex) { } } initSlidersSmooth(); try { Thread.sleep(1000); } catch (InterruptedException ex) { } powerToggleButton.setSelected(true); try { Thread.sleep(1000); } catch (InterruptedException ex) { } campaignComboBox.setSelectedItem(campaignIdParam); campaignComboBox.setEnabled(false); if (callCenterIsNetManaged) { netManagerOutboundServerToggleButton.setEnabled(callCenterIsNetManaged); netManagerOutboundServerToggleButton.setSelected(callCenterIsNetManaged); enableOutboundNetManagerServer(true); } runCampaignToggleButton.setSelected(true); runCampaign(campaignIdParam); } else { usage(); System.exit(0); } } }); outboundCampaignThread.setName("outboundCampaignThread"); outboundCampaignThread.setDaemon(runThreadsAsDaemons); outboundCampaignThread.setPriority(7); outboundCampaignThread.start(); }
From source file:ECallCenter21.java
/** * * @param callCenterModeParam//from w w w . ja v a 2s .c o m * @param managedModeParam * @throws SQLException * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws Exception */ public ECallCenter21(final String callCenterModeParam, final boolean managedModeParam) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, Exception { this(); // Execute default constructor while (!defaultConstructorIsReady) { try { Thread.sleep(100); } catch (InterruptedException ex) { } } Thread inboundCampaignThread = new Thread(allThreadsGroup, new Runnable() { @Override public void run() { callCenterIsNetManaged = managedModeParam; if (callCenterModeParam.equals("Inbound")) { positionWindow("Right"); callCenterIsOutBound = false; try { Thread.sleep(mediumMessagePeriod); } catch (InterruptedException ex) { } setPowerOn(true); while (getCallCenterStatus() != POWEREDON) { try { Thread.sleep(1000); } catch (InterruptedException ex) { } } powerToggleButton.setSelected(true); register(); initSlidersSmooth(); } else if (callCenterModeParam.equals("Outbound")) { positionWindow("Left"); callCenterIsOutBound = true; try { Thread.sleep(mediumMessagePeriod); } catch (InterruptedException ex) { } setPowerOn(true); while (getCallCenterStatus() != POWEREDON) { try { Thread.sleep(1000); } catch (InterruptedException ex) { } } powerToggleButton.setSelected(true); if (callCenterIsNetManaged) { netManagerOutboundServerToggleButton.setEnabled(callCenterIsNetManaged); netManagerOutboundServerToggleButton.setSelected(callCenterIsNetManaged); enableOutboundNetManagerServer(true); } initSlidersSmooth(); } else { positionWindow("Right"); callCenterIsOutBound = true; try { Thread.sleep(mediumMessagePeriod); } catch (InterruptedException ex) { } setPowerOn(true); while (getCallCenterStatus() != POWEREDON) { try { Thread.sleep(1000); } catch (InterruptedException ex) { } } powerToggleButton.setSelected(true); initSlidersSmooth(); try { Thread.sleep(5000); } catch (InterruptedException ex) { } } } }); inboundCampaignThread.setName("inboundCampaignThread"); inboundCampaignThread.setDaemon(runThreadsAsDaemons); inboundCampaignThread.setPriority(7); inboundCampaignThread.start(); }
From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java
public void runUpdateTask() { Thread localThread = new Thread(new CheckUpdate()); localThread.setPriority(1); localThread.start();/*from w w w. j av a 2 s. c o m*/ }
From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java
public void app_scanning() { if (plia != null) { Thread localThread = new Thread(new AppScanning()); localThread.setPriority(10); localThread.start();//from w ww . jav a 2 s.c o m } }
From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java
public void toolbar_refresh_click() { if (plia != null) { Thread localThread = new Thread(new AppScanning()); localThread.setPriority(10); localThread.start();/* ww w .j a v a2 s . c o m*/ refresh = true; plia.refreshPkgs(true); } }
From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java
public void contexttoolbarcreateframework() { System.out.println("LuckyPatcher: Core patch start!"); Thread localThread = new Thread(new Runnable() { public void run() { listAppsFragment.this.runToMain(new Runnable() { public void run() { listAppsFragment.showDialogLP(11); listAppsFragment.progress2.setCancelable(false); listAppsFragment.progress2.setMessage(Utils.getText(2131165747)); }/* w w w . j a va 2 s . c om*/ }); try { listAppsFragment.str = ""; corepatch.main(new String[] { "all", listAppsFragment.rebuldApk, listAppsFragment.rebuldApk, listAppsFragment.getInstance().getFilesDir().getAbsolutePath(), "framework" }); if (corepatch.not_found_bytes_for_patch) { listAppsFragment.this.showMessage(Utils.getText(2131165495), Utils.getText(2131165780)); } System.out.println(listAppsFragment.str); } catch (Exception localException) { for (;;) { localException.printStackTrace(); } } listAppsFragment.this.runToMain(new Runnable() { public void run() { listAppsFragment.removeDialogLP(11); listAppsFragment.frag.getDir( Utils.getDirs(new File(listAppsFragment.rebuldApk)).getAbsolutePath(), listAppsFragment.frag.filebrowser, false); if ((new File(listAppsFragment.rebuldApk.replace("/core.odex", "/core-patched.odex") .replace("/core.jar", "/core-patched.jar") .replace("/services.odex", "/services-patched.odex") .replace("/services.jar", "/services-patched.jar") .replace("/core-libart.jar", "/core-libart-patched.jar") .replace("/core-libart.odex", "/core-libart-patched.odex") .replace("/boot.oat", "/boot-patched.oat")).exists()) && (!new File(listAppsFragment.rebuldApk).exists())) { listAppsFragment.this.showMessage(Utils.getText(2131165748), new File(listAppsFragment.rebuldApk).getName() + " " + Utils.getText(2131165778) + " " + new File(listAppsFragment.rebuldApk .replace("/core.odex", "/core-patched.odex") .replace("/core.jar", "/core-patched.jar") .replace("/services.odex", "/services-patched.odex") .replace("/services.jar", "/services-patched.jar") .replace("/core-libart.jar", "/core-libart-patched.jar") .replace("/boot.oat", "/boot-patched.oat")).getName()); } while (corepatch.not_found_bytes_for_patch) { return; } listAppsFragment.this.showMessage(Utils.getText(2131165748), Utils.getText(2131165732)); } }); } }); localThread.setPriority(10); localThread.start(); }