Synchronize an entire method by putting the synchronized modifier in the method's declaration. : Synchronize « Thread « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Thread » Synchronize 
7.9.2.Synchronize an entire method by putting the synchronized modifier in the method's declaration.
To execute the method, a thread must acquire the lock of the object that owns the method.

 class MyData {
   private boolean request;
   private String  data;

   public synchronized void
   storeMessage(String data) {
      request = true;
      this.data = data;
   }

  public synchronized String retrieveMessage() {
    request = false;
    return data;
  }
 }
7.9.Synchronize
7.9.1.synchronized code
7.9.2.Synchronize an entire method by putting the synchronized modifier in the method's declaration.
7.9.3.Synchronizing Part of a Method
7.9.4.An example for deadlock
7.9.5.To synchronize part of a method preceded by synchronized(this).
7.9.6.When used with a code block, synchronized must be applied to an object.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.