lockCanvas和Android的同步 [英] lockCanvas and synchronization in Android

查看:153
本文介绍了lockCanvas和Android的同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Override
   public void run()
   {
     Canvas canvas =  null; // used for drawing               {
     while  (threadIsRunning)
     {
        try
        {
         canvas = surfaceHolder.lockCanvas(null);  // line 1                               

           synchronized(surfaceHolder)             // line 2

                { //do something .....

                }

           }
        }
      }

据许多岗位和博客 lockCanvas 将在画布上的锁,这样帆布多址接入是不可能的, synchronized块被使用,所以没有其他线程
画在画布上。

According to many post and blogs lockCanvas will make a lock on canvas so that multiple access to canvas is not possible and synchronized block is used so that no other thread draw on canvas ..

疑问句是,如果其他的线程是由迫使它等待具有由锁帆布帆布pvented $ P $。
那么什么是需要同步块线程不能达到该块,因为它被封锁

Ques is if other thread is prevented from having a canvas by lock canvas by forcing it to wait . Then what is need of synchronized block as thread cannot reach this block as it is blocked

推荐答案

我想,如果 lockCanvas 无法获得锁定,它将只返回键,将继续执行。

I think, if lockCanvas cannot obtain lock it will just return null and execution will continue.

这篇关于lockCanvas和Android的同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆