Coder Social home page Coder Social logo

Comments (13)

cekowu avatar cekowu commented on July 23, 2024

感觉是什么被锁了一样,只有清除数据或者重新安装才能加载图片

from xutils3.

cekowu avatar cekowu commented on July 23, 2024

当图片加载特别多的时候,这个问题可以复现,但log中又没有抛出什么异常,感觉特别奇怪,这个问题应该比较严重

from xutils3.

cekowu avatar cekowu commented on July 23, 2024

@OverRide
protected final ResultType doBackground() throws Throwable {
UtilLog.d("TaskProxy doBackground run");
this.onWaiting();
PriorityRunnable runnable = new PriorityRunnable(
task.getPriority(),
new Runnable() {
@OverRide
public void run() {
try {
UtilLog.d("TaskProxy doBackground run");
// 等待过程中取消
if (callOnCanceled || TaskProxy.this.isCancelled()) {
throw new Callback.CancelledException("");
}

                        // start running
                        TaskProxy.this.onStarted();

                        if (TaskProxy.this.isCancelled()) { // 开始时取消
                            throw new Callback.CancelledException("");
                        }

                        // 执行task, 得到结果.
                        task.setResult(task.doBackground());
                        TaskProxy.this.setResult(task.getResult());

                        // 未在doBackground过程中取消成功
                        if (TaskProxy.this.isCancelled()) {
                            throw new Callback.CancelledException("");
                        }

                        // 执行成功
                        TaskProxy.this.onSuccess(task.getResult());
                    } catch (Callback.CancelledException cex) {
                        TaskProxy.this.onCancelled(cex);
                    } catch (Throwable ex) {
                        TaskProxy.this.onError(ex, false);
                    }

                    // finished
                    TaskProxy.this.onFinished();
                }
            });
    this.executor.execute(runnable);
    return null;

我跟踪了一下日志,发现线程池添加runnable 线程后,但一直处于wait状态,初步估计线程池占满了。死循环了没有释放导致的

from xutils3.

cekowu avatar cekowu commented on July 23, 2024

这种情况在图片较多的应用中肯定是会出现的,我在另一个issue中提到的应该有取消所有图片加载的线程功能或者清空线程池的功能,图片加载这种功能它和普通的网络数据线程有一些不太相同,图片加载线程使用的频率远远比数据线程更多,所以这种管理可能会出现我上述提到的这个issue。

###################################
Re: 图片加载会在 a.页面被回收 或 b.ImageView被回收 或者 c.ImageView的连接被替换 的时候自动停止.

from xutils3.

wyouflf avatar wyouflf commented on July 23, 2024

尝试更新到最新版本.
任何锁重启都没有了, 这个应该和图片多少没关系, 我们的应用也是每页有很多图, 没遇到这个问题, 能发给我一个演示用的出错的demo吗, 我测试一下, 帮你解决这个问题. [email protected]

from xutils3.

cekowu avatar cekowu commented on July 23, 2024

恩可能传不了demo给你,主要是我们外网的图片太少复现不了bug,内网的你也看不了。我这边对库做了一些小调整,比如说图片连接超时的时间改成了5秒,然后对于线程池这块在执行任务之前purge一下。
经过测试不在复现上面的issue
出现这种情况下我打debug看了下mThreadPoolExecutor.getActiveCount() 和mThreadPoolExecutor.getCorePoolSize()数量相等,线程池繁忙。

from xutils3.

wyouflf avatar wyouflf commented on July 23, 2024

检查一下convertView是否被正确重用.
内网应该更快, 不会出现繁忙才对. 更新到最新版本试试.

参数和用法?

如果你的convertView被正确重用, 被重用的ImageView的下载会被立即终止, 以容纳更多的下载.
或者你的页面上图片很多, 而且下载链接特别慢, 一直处于阻塞状态, 图片无法下载.
或者你的应用里有其他使用xUtils的下载一直占用下载通道, 导致下载阻塞.

还有如果你的代码里存在持有View, 使之无法正常被系统回收的代码, 也可能导致图片加载无法被终止.

我对加载超时和停止策略再做一些优化, 明天更新下试试.

from xutils3.

cekowu avatar cekowu commented on July 23, 2024

更新的到了新的版本后测试,发现这种情况出现在经常查看大图的时候会有这个问题

#######################
Re: 尝试更新到3.1.10或更高的版本

from xutils3.

cekowu avatar cekowu commented on July 23, 2024

好的谢谢

from xutils3.

cekowu avatar cekowu commented on July 23, 2024

我检查了一下大图adpter的code,发现使用ViewPager来实现的
public class PopViewPagerAdapter extends PagerAdapter {
private Context mContext;
private List<Map<String, String>> pictureUrls;
private int imageW, imageH;

public PopViewPagerAdapter(List<Map<String, String>> pictureUrls,
        Context mContext, int imageW, int imageH) {
    this.pictureUrls = pictureUrls;
    this.mContext = mContext;
    this.imageH = imageH;
    this.imageW = imageW;
}

@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
    ((ViewPager) arg0).removeView((View) arg2);
}

@Override
public void finishUpdate(View arg0) {
}

@Override
public int getCount() {
    if (pictureUrls != null) {
        return pictureUrls.size();
    }
    return 0;
}

@Override
public Object instantiateItem(View arg0, int arg1) {
    View view = ((LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
            R.layout.pop_view_page_item, null);
    final DragImageView item_image = (DragImageView) view
            .findViewById(R.id.item_image);
    item_image.getViewTreeObserver().addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    // TODO Auto-generated method stub
                    item_image.setScreen_H(imageH);
                    item_image.setScreen_W(imageW);
                }
            });

    item_image.setAdjustViewBounds(true);
    item_image.setMaxHeight(this.imageH-Utilities.dip2px(mContext, 25));
    item_image.setMaxWidth(this.imageW);

    ImageOptions imageOptions = new ImageOptions.Builder()
    // 加载中或错误图片的ScaleType
    // .setPlaceholderScaleType(ImageView.ScaleType.MATRIX)
    // 默认自动适应大小
    .setIgnoreGif(true)
    .setLoadingDrawableId(R.drawable.img_dufult)
    .setFailureDrawableId(R.drawable.img_damage)

// .setImageScaleType(ImageView.ScaleType.FIT_XY)
.build();

    x.image().bind(item_image,pictureUrls.get(arg1).get("url"),imageOptions, new CommonCallback<Drawable>(){

        @Override
        public void onSuccess(Drawable result) {
            Bitmap response=Tools.drawableToBitmap(result);
            int picWidth=response.getWidth();
            int picHeight=response.getHeight();
            if(picWidth>=(imageW*1/2)){
                int scalH=0;
                double proportion = 0.00;
                if(picWidth>imageW){
                    proportion = picWidth/imageW;
                    scalH = (int) (picHeight * proportion);
                }else{
                    double tempScreenW = imageW + 0.0000;
                    proportion = tempScreenW/picWidth;
                    scalH = (int) (picHeight * proportion);
                }
                int actScreenH=Utilities.getScreenHigh(mContext)-Utilities.dip2px(mContext, 25);
                //如果缩放后的图片高度大于屏幕的实际高度
                if(scalH>actScreenH){
                    scalH=actScreenH;
                    item_image.setAdjustViewBounds(true);
                }
                LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(imageW,scalH);
                layoutParams.gravity=Gravity.CENTER;
                item_image.setLayoutParams(layoutParams);
            }else {
                LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
                layoutParams.gravity=Gravity.CENTER;
                item_image.setLayoutParams(layoutParams);

            }
            item_image.setImageBitmap(response);
        }

        @Override
        public void onError(Throwable ex, boolean isOnCallback) {
            // TODO Auto-generated method stub
            UtilLog.d("onError ex=="+ex.getMessage());
            for(StackTraceElement en:ex.getStackTrace()){
                UtilLog.d("onError ex=="+en.getClassName()+en.getMethodName()+en.getLineNumber());
            }
        }

        @Override
        public void onCancelled(CancelledException cex) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onFinished() {
            // TODO Auto-generated method stub

        }

    });


    ((ViewPager) arg0).addView(view);
    return view;
}

@Override
public boolean isViewFromObject(View arg0, Object arg1) {
    return (arg0 == arg1);
}

@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}

}

from xutils3.

cekowu avatar cekowu commented on July 23, 2024

有可能如你所说view的重用问题

from xutils3.

cekowu avatar cekowu commented on July 23, 2024

使用viewpager 加载图片,由于adpter没有重用view,而且会自动缓存下一页导致的吧,有没有好的建议

from xutils3.

wyouflf avatar wyouflf commented on July 23, 2024

viewpager好像可以控制初始化时预加载的页面的个数.
更新到最新版以解决加个兼容问题.

from xutils3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.