Example usage for android.os Process THREAD_PRIORITY_BACKGROUND

List of usage examples for android.os Process THREAD_PRIORITY_BACKGROUND

Introduction

In this page you can find the example usage for android.os Process THREAD_PRIORITY_BACKGROUND.

Prototype

int THREAD_PRIORITY_BACKGROUND

To view the source code for android.os Process THREAD_PRIORITY_BACKGROUND.

Click Source Link

Document

Standard priority background threads.

Usage

From source file:com.android.volley.NetworkDispatcher.java

@Override
public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    while (true) {
        long startTimeMs = SystemClock.elapsedRealtime();
        Request<?> request;
        try {//w  w  w  . jav  a2s  .  c  om
            // Take a request from the queue.
            request = mQueue.take();
        } catch (InterruptedException e) {
            // We may have been interrupted because it was time to quit.
            if (mQuit) {
                return;
            }
            continue;
        }

        try {
            request.addMarker("network-queue-take");

            // If the request was cancelled already, do not perform the
            // network request.
            if (request.isCanceled()) {
                request.finish("network-discard-cancelled");
                continue;
            }

            addTrafficStatsTag(request);

            // Perform the network request.
            NetworkResponse networkResponse = mNetwork.performRequest(request);
            request.addMarker("network-http-complete");

            // If the server returned 304 AND we delivered a response already,
            // we're done -- don't deliver a second identical response.
            if (networkResponse.notModified && request.hasHadResponseDelivered()) {
                request.finish("not-modified");
                continue;
            }

            // Parse the response here on the worker thread.
            Response<?> response = request.parseNetworkResponse(networkResponse);
            request.addMarker("network-parse-complete");

            // Write to cache if applicable.
            // TODO: Only update cache metadata instead of entire record for 304s.
            if (request.shouldCache() && response.cacheEntry != null) {
                mCache.put(request.getCacheKey(), response.cacheEntry);
                request.addMarker("network-cache-written");
            }

            // Post the response back.
            request.markDelivered();
            mDelivery.postResponse(request, response);
        } catch (VolleyError volleyError) {
            volleyError.setNetworkTimeMs(SystemClock.elapsedRealtime() - startTimeMs);
            parseAndDeliverNetworkError(request, volleyError);
        } catch (Exception e) {
            VolleyLog.e(e, "Unhandled exception %s", e.toString());
            VolleyError volleyError = new VolleyError(e);
            volleyError.setNetworkTimeMs(SystemClock.elapsedRealtime() - startTimeMs);
            mDelivery.postError(request, volleyError);
        }
    }
}

From source file:com.siahmsoft.soundroid.sdk7.provider.tracks.TracksUpdater.java

public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    final ImageUtilities.ExpiringBitmap expiring = new ImageUtilities.ExpiringBitmap();

    while (!mStopped) {
        try {/*w ww  .j a  va 2s.  c  om*/
            final String trackId = mQueue.take();

            final Long lastCheck = sLastChecks.get(trackId);

            if (lastCheck != null && lastCheck + ONE_DAY >= System.currentTimeMillis()) {
                continue;
            }

            sLastChecks.put(trackId, System.currentTimeMillis());

            final TracksStore.Track track = TracksManager.findTrack(mResolver, trackId);

            if (track.getmLastModified() == null || track.getmArtworkUrl() == null) {
                continue;
            }

            if (trackArtworkUpdated(track, expiring) && expiring.lastModified != null) {
                ImageUtilities.deleteCachedCover(trackId);
                final Bitmap bitmap = track.loadCover(TracksStore.ImageSize.TINY);
                ImportUtilities.addTrackCoverToCache(track, bitmap);

                mValues.put(TracksStore.Track.LAST_MODIFIED, expiring.lastModified.getTimeInMillis());
                mArguments[0] = trackId;
                mResolver.update(TracksStore.Track.CONTENT_URI, mValues, mSelection, mArguments);
            }

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}

From source file:biz.varkon.shelvesom.provider.toys.ToysUpdater.java

public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    final ImageUtilities.ExpiringBitmap expiring = new ImageUtilities.ExpiringBitmap();

    while (!mStopped) {
        try {//from   w ww.  ja v  a  2s  . co m
            final String toyId = mQueue.take();

            final Long lastCheck = sLastChecks.get(toyId);
            if (lastCheck != null && (lastCheck + ONE_DAY) >= System.currentTimeMillis()) {
                continue;
            }
            sLastChecks.put(toyId, System.currentTimeMillis());

            final ToysStore.Toy toy = ToysManager.findToy(mResolver, toyId, null);

            if (toy == null)
                continue;

            final String imgURL = Preferences.getImageURLForUpdater(toy);

            if (toy.getLastModified() == null || imgURL == null) {
                continue;
            }

            if (toyCoverUpdated(toy, expiring) && expiring.lastModified != null) {
                ImageUtilities.deleteCachedCover(toyId);

                final Bitmap bitmap = Preferences.getBitmapForManager(toy);

                ImportUtilities.addCoverToCache(toy.getInternalId(), bitmap);

                if (bitmap != null)
                    bitmap.recycle();

                mValues.put(BaseItem.LAST_MODIFIED, expiring.lastModified.getTimeInMillis());
                mArguments[0] = toyId;
                mResolver.update(ToysStore.Toy.CONTENT_URI, mValues, mSelection, mArguments);
            }

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}

From source file:biz.varkon.shelvesom.provider.tools.ToolsUpdater.java

public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    final ImageUtilities.ExpiringBitmap expiring = new ImageUtilities.ExpiringBitmap();

    while (!mStopped) {
        try {/*from  w  w  w  .  j a  v  a  2  s  .com*/
            final String toolId = mQueue.take();

            final Long lastCheck = sLastChecks.get(toolId);
            if (lastCheck != null && (lastCheck + ONE_DAY) >= System.currentTimeMillis()) {
                continue;
            }
            sLastChecks.put(toolId, System.currentTimeMillis());

            final ToolsStore.Tool tool = ToolsManager.findTool(mResolver, toolId, null);

            if (tool == null)
                continue;

            final String imgURL = Preferences.getImageURLForUpdater(tool);

            if (tool.getLastModified() == null || imgURL == null) {
                continue;
            }

            if (toolCoverUpdated(tool, expiring) && expiring.lastModified != null) {
                ImageUtilities.deleteCachedCover(toolId);

                final Bitmap bitmap = Preferences.getBitmapForManager(tool);

                ImportUtilities.addCoverToCache(tool.getInternalId(), bitmap);

                if (bitmap != null)
                    bitmap.recycle();

                mValues.put(BaseItem.LAST_MODIFIED, expiring.lastModified.getTimeInMillis());
                mArguments[0] = toolId;
                mResolver.update(ToolsStore.Tool.CONTENT_URI, mValues, mSelection, mArguments);
            }

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}

From source file:biz.varkon.shelvesom.provider.music.MusicUpdater.java

public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    final ImageUtilities.ExpiringBitmap expiring = new ImageUtilities.ExpiringBitmap();

    while (!mStopped) {
        try {/* w w  w  .jav  a  2s .c o  m*/
            final String musicId = mQueue.take();

            final Long lastCheck = sLastChecks.get(musicId);
            if (lastCheck != null && (lastCheck + ONE_DAY) >= System.currentTimeMillis()) {
                continue;
            }
            sLastChecks.put(musicId, System.currentTimeMillis());

            final MusicStore.Music music = MusicManager.findMusic(mResolver, musicId, null);

            if (music == null)
                continue;

            final String imgURL = Preferences.getImageURLForUpdater(music);

            if (music.getLastModified() == null || imgURL == null) {
                continue;
            }

            if (musicCoverUpdated(music, expiring) && expiring.lastModified != null) {
                ImageUtilities.deleteCachedCover(musicId);

                final Bitmap bitmap = Preferences.getBitmapForManager(music);

                ImportUtilities.addCoverToCache(music.getInternalId(), bitmap);

                if (bitmap != null)
                    bitmap.recycle();

                mValues.put(BaseItem.LAST_MODIFIED, expiring.lastModified.getTimeInMillis());
                mArguments[0] = musicId;
                mResolver.update(MusicStore.Music.CONTENT_URI, mValues, mSelection, mArguments);
            }

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}

From source file:biz.varkon.shelvesom.provider.movies.MoviesUpdater.java

public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    final ImageUtilities.ExpiringBitmap expiring = new ImageUtilities.ExpiringBitmap();

    while (!mStopped) {
        try {/*from w w w .ja v a 2s. com*/
            final String movieId = mQueue.take();

            final Long lastCheck = sLastChecks.get(movieId);
            if (lastCheck != null && (lastCheck + ONE_DAY) >= System.currentTimeMillis()) {
                continue;
            }
            sLastChecks.put(movieId, System.currentTimeMillis());

            final MoviesStore.Movie movie = MoviesManager.findMovie(mResolver, movieId, null);

            if (movie == null)
                continue;

            final String imgURL = Preferences.getImageURLForUpdater(movie);

            if (movie.getLastModified() == null || imgURL == null) {
                continue;
            }

            if (movieCoverUpdated(movie, expiring) && expiring.lastModified != null) {
                ImageUtilities.deleteCachedCover(movieId);

                final Bitmap bitmap = Preferences.getBitmapForManager(movie);

                ImportUtilities.addCoverToCache(movie.getInternalId(), bitmap);

                if (bitmap != null)
                    bitmap.recycle();

                mValues.put(BaseItem.LAST_MODIFIED, expiring.lastModified.getTimeInMillis());
                mArguments[0] = movieId;
                mResolver.update(MoviesStore.Movie.CONTENT_URI, mValues, mSelection, mArguments);
            }

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}

From source file:biz.varkon.shelvesom.provider.gadgets.GadgetsUpdater.java

public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    final ImageUtilities.ExpiringBitmap expiring = new ImageUtilities.ExpiringBitmap();

    while (!mStopped) {
        try {//from w  w w .j a v a  2 s  . c  o m
            final String gadgetId = mQueue.take();

            final Long lastCheck = sLastChecks.get(gadgetId);
            if (lastCheck != null && (lastCheck + ONE_DAY) >= System.currentTimeMillis()) {
                continue;
            }
            sLastChecks.put(gadgetId, System.currentTimeMillis());

            final GadgetsStore.Gadget gadget = GadgetsManager.findGadget(mResolver, gadgetId, null);

            if (gadget == null)
                continue;

            final String imgURL = Preferences.getImageURLForUpdater(gadget);

            if (gadget.getLastModified() == null || imgURL == null) {
                continue;
            }

            if (gadgetCoverUpdated(gadget, expiring) && expiring.lastModified != null) {
                ImageUtilities.deleteCachedCover(gadgetId);

                final Bitmap bitmap = Preferences.getBitmapForManager(gadget);

                ImportUtilities.addCoverToCache(gadget.getInternalId(), bitmap);

                if (bitmap != null)
                    bitmap.recycle();

                mValues.put(BaseItem.LAST_MODIFIED, expiring.lastModified.getTimeInMillis());
                mArguments[0] = gadgetId;
                mResolver.update(GadgetsStore.Gadget.CONTENT_URI, mValues, mSelection, mArguments);
            }

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}

From source file:biz.varkon.shelvesom.provider.apparel.ApparelUpdater.java

public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    final ImageUtilities.ExpiringBitmap expiring = new ImageUtilities.ExpiringBitmap();

    while (!mStopped) {
        try {/*from   w w  w  . j ava 2 s.  co m*/
            final String apparelId = mQueue.take();

            final Long lastCheck = sLastChecks.get(apparelId);
            if (lastCheck != null && (lastCheck + ONE_DAY) >= System.currentTimeMillis()) {
                continue;
            }
            sLastChecks.put(apparelId, System.currentTimeMillis());

            final ApparelStore.Apparel apparel = ApparelManager.findApparel(mResolver, apparelId, null);

            if (apparel == null)
                continue;

            final String imgURL = Preferences.getImageURLForUpdater(apparel);

            if (apparel.getLastModified() == null || imgURL == null) {
                continue;
            }

            if (apparelCoverUpdated(apparel, expiring) && expiring.lastModified != null) {
                ImageUtilities.deleteCachedCover(apparelId);

                final Bitmap bitmap = Preferences.getBitmapForManager(apparel);

                ImportUtilities.addCoverToCache(apparel.getInternalId(), bitmap);

                if (bitmap != null)
                    bitmap.recycle();

                mValues.put(BaseItem.LAST_MODIFIED, expiring.lastModified.getTimeInMillis());
                mArguments[0] = apparelId;
                mResolver.update(ApparelStore.Apparel.CONTENT_URI, mValues, mSelection, mArguments);
            }

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}

From source file:biz.varkon.shelvesom.provider.software.SoftwareUpdater.java

public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    final ImageUtilities.ExpiringBitmap expiring = new ImageUtilities.ExpiringBitmap();

    while (!mStopped) {
        try {/*  w w w  .  j  a  v  a 2s .c  o m*/
            final String softwareId = mQueue.take();

            final Long lastCheck = sLastChecks.get(softwareId);
            if (lastCheck != null && (lastCheck + ONE_DAY) >= System.currentTimeMillis()) {
                continue;
            }
            sLastChecks.put(softwareId, System.currentTimeMillis());

            final SoftwareStore.Software software = SoftwareManager.findSoftware(mResolver, softwareId, null);

            if (software == null)
                continue;

            final String imgURL = Preferences.getImageURLForUpdater(software);

            if (software.getLastModified() == null || imgURL == null) {
                continue;
            }

            if (softwareCoverUpdated(software, expiring) && expiring.lastModified != null) {
                ImageUtilities.deleteCachedCover(softwareId);

                final Bitmap bitmap = Preferences.getBitmapForManager(software);

                ImportUtilities.addCoverToCache(software.getInternalId(), bitmap);

                if (bitmap != null)
                    bitmap.recycle();

                mValues.put(BaseItem.LAST_MODIFIED, expiring.lastModified.getTimeInMillis());
                mArguments[0] = softwareId;
                mResolver.update(SoftwareStore.Software.CONTENT_URI, mValues, mSelection, mArguments);
            }

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}

From source file:biz.varkon.shelvesom.provider.books.BooksUpdater.java

public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    final ImageUtilities.ExpiringBitmap expiring = new ImageUtilities.ExpiringBitmap();

    while (!mStopped) {
        try {/* w w w.j  a va  2  s .  c  o m*/
            final String bookId = mQueue.take();

            final Long lastCheck = sLastChecks.get(bookId);
            if (lastCheck != null && (lastCheck + ONE_DAY) >= System.currentTimeMillis()) {
                continue;
            }
            sLastChecks.put(bookId, System.currentTimeMillis());

            final BooksStore.Book book = BooksManager.findBook(mResolver, bookId, null);

            if (book == null)
                continue;

            final String imgURL = Preferences.getImageURLForUpdater(book);

            if (book.getLastModified() == null || imgURL == null) {
                continue;
            }

            if (bookCoverUpdated(book, expiring) && expiring.lastModified != null) {
                ImageUtilities.deleteCachedCover(bookId);

                final Bitmap bitmap = Preferences.getBitmapForManager(book);

                ImportUtilities.addCoverToCache(book.getInternalId(), bitmap);

                if (bitmap != null)
                    bitmap.recycle();

                mValues.put(BaseItem.LAST_MODIFIED, expiring.lastModified.getTimeInMillis());
                mArguments[0] = bookId;
                mResolver.update(BooksStore.Book.CONTENT_URI, mValues, mSelection, mArguments);
            }

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // Ignore
        }
    }
}