Q:

Synchronized Android surface view

I am kind of new to java and android.
Now I am using the canvas to draw on the surface view because the faster speed than customer view.
But when it comes to synchronized the surface view in android I am getting kind of confuse
I take this link as the reference
http://android-er.blogspot.com/2010/05/android-surfaceview.html
also the android lunar lander 
I have  two  version that slightly modified form example when I write the surfaceview rendering thread run method part, but I am not sure which one is more correct in concept. They both works,
But I just want to clear my concepts.
Thank for any help and suggestions in advanced and if i have ask question in wrong way please also corrected me   :)
version1 :
protected void run()
{
  while (isRunning) 
 {       
          if(RenderThreadSurfaceHolder.getSurface().isValid())
          {  
            Canvas Draw = null;
            try 
            {
              Draw =RenderThreadSurfaceHolder.lockCanvas(null);
              synchronized (RenderThreadSurfaceHolder){     
                  if(Draw!=null)
                  {                                                                       
                       RenderThreadSurfaceView.onDraw(Draw);
                  }  
              }
            }
            finally{                    
              if(Draw!=null) 
              {                                                    
                      RenderThreadSurfaceHolder.unlockCanvasAndPost(Draw);
              }
            }
        }
    }
}  

version 2 :  
protected void run()
{
  while (isRunning) 
 {       
          Canvas Draw = null;  
                try 
                {    

                     synchronized (RenderThreadSurfaceHolder) 
                     {       
                             if(RenderThreadSurfaceHolder.getSurface().isValid())
                             { 

                                   Draw=RenderThreadSurfaceHolder.lockCanvas(null);
                                   if(Draw!=null)
                                   {   
                                      RenderThreadSurfaceView.onDraw(Draw);
                                   } 

                             }  
                     }
                 }   
                 finally 
                 {

                             if (Draw != null) 
                             {
                                 RenderThreadSurfaceHolder.unlockCanvasAndPost(Draw);
                             }
                 }
    }
}  

Edit
In additional synchronized the surface view I also want to add on a lock to control the data that share data between Activity and OnDraw method
Because I Think synchronized lots of data and lots process function is too much overhead
So I want to just synchronized a boolean , But What I do research on the Internet say that
Synchronized boolean is really not a good idea //still confusion me a lot
such as 
synchronized (Check) 
{
   Check=true;   
}

But if I do something like below
private static lock Lock; //declare in the Activity

public synchronized void setlock(boolean newlock) 
{
  if (newlock!=lock){
    lock = newlock;
  } 
}

public synchronized boolean isTrue() {
    return lock;
}

Is that still not a good idea?
My concept is want to add the lock between the process function and OnDraw method :

A:

This is a very subjective question, but I would go with 1.  
The first approach has a tighter synchronized(RenderThreadSurfaceHolder); less code requires synchronization and this can help avoid blocking issues.
Besides that, it seems to be mostly ordering.  In solution 1 it also makes sense to call           if(RenderThreadSurfaceHolder.getSurface().isValid()) as soon as possible, because if the surface is invalid then nothing can happen anyways.  This avoids unnecessary if/else checks.
yeah, synchronization doesn't work on a boolean.  The reason is that BOOLEAN.TRUE and BOOLEAN.FALSE are static constants.  
The idea is that when you synchronize a reference variable, any other threads that try to use that must wait until the currently running synchronized block ends.  As your boolean references either BOOLEAN.TRUE or BOOLEAN.FALSE, as soon as you synchronize on a second boolean you will start to see issues.
continue to synchronize on the RenderThreadSurfaceHolder, that is how I do it and how I have seen it done.
Why would you want to add a lock between drawing and updating?  Maybe if I knew the reason, I could help ya out with another approach.  Also, That will just add overhead, remember you want to keep your game loop as tight as possible.

