Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

putBitmap and getBitmap on non-UIThread #8

Open
booker0108 opened this issue Nov 26, 2014 · 1 comment
Open

putBitmap and getBitmap on non-UIThread #8

booker0108 opened this issue Nov 26, 2014 · 1 comment

Comments

@booker0108
Copy link

Hi all, I am experiencing lag issue loading large images with my view pager.

I think the putBitmap and getBitmap method should run on another thread.

Any implementation?

@imknown
Copy link

imknown commented Sep 18, 2016

I found this issue too...
I've to fixed this UI thread i/o lag.
But now it has GC lag instead,
and really NOT use the disk cache asynchronous.
See #10 and #12 .

private static final short THREAD_POOL_SIZE = 15;
private ExecutorService executor;

public VolleyImageCache() {
    executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
}

@Override
public void putBitmap(final String key, final Bitmap data) {
    executor.execute(new Runnable(){
        @Override
        public void run() {
            // TODO put Bitmap
        }
    }
}

@Override
public Bitmap getBitmap(final String key) {
    FutureTask<Bitmap> watcher = new FutureTask<>(new Callable<Bitmap>() {
        @Override
        public Bitmap call() throws Exception {
            Bitmap bitmap = null;
            // TODO get Bitmap
            return bitmap;
        }
    }

//  new Thread(watcher).start();
    executor.execute(watcher);

    Bitmap bitmap = null;
    try {
        bitmap = watcher.get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

    return bitmap;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants