[英]Why is my app suspending threads and how can I fix this?
这是我的代码:
public class CustomSwipeAdaptor extends PagerAdapter {
private int[] image_resources={R.drawable.aa,R.drawable.bb,R.drawable.cc};
private Context ctx;
private LayoutInflater layoutInflater;
public CustomSwipeAdaptor(Context ctx)
{
this.ctx=ctx;
}
@Override
public int getCount() {
return image_resources.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return (view==(LinearLayout)object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater=(LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
View item_view=layoutInflater.inflate(R.layout.swipe_layout,container,false);
ImageView imageView=(ImageView)item_view.findViewById(R.id.image_view);
imageView.setImageResource(image_resources[position]);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}
}
public class Chapter1 extends AppCompatActivity{
ViewPager viewPager;
CustomSwipeAdaptor adaptor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chapter1);
viewPager=(ViewPager)findViewById(R.id.view_pager);
adaptor=new CustomSwipeAdaptor(this);
viewPager.setAdapter(adaptor);
}
}
这是我的logcat:
06-12 18:45:05.631 341-349/com.example.kips.itapps W/art: Suspending all threads took: 7.170ms
06-12 18:45:27.677 341-349/com.example.kips.itapps W/art: Suspending all threads took: 6.168ms
06-12 18:47:31.577 341-349/com.example.kips.itapps W/art: Suspending all threads took: 7.052ms
06-12 18:48:36.275 341-349/com.example.kips.itapps W/art: Suspending all threads took: 5.650ms
06-12 18:56:21.208 341-349/com.example.kips.itapps W/art: Suspending all threads took: 8.523ms
这在很大程度上是无害的。 从这里开始
Java代码堆是一个共享资源。 对于ART中的GC暂停,必须暂停线程,以便它们不会更改堆并破坏GC不变量。 要挂起线程,GC会修改线程局部变量,然后线程会观察到此更改并放弃mutator锁定,然后GC将独占地保持锁定并运行。 当线程被挂起而其他线程放弃它们的mutator锁的份额时,它对jank的重要性是线程及时响应。 5ms几乎是16ms帧的1/3,因此当线程悬挂缓慢时,ART会发出警告。 正如+ Aladin Q所说,这可能会带来很多负担。 如果它经常发生或没有负载,它可能是一个可能导致jank的bug的证据。
除非你有严重的问题阻止你的应用程序实现其目标,否则它是良性的,以及其他几个类似的日志输出 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.