Which object's monitor does a synchronized method acquire?

from the Java Tutorial for concurrency programming:
" When a thread invokes a synchronized method, it automatically acquires the intrinsic lock _for that method's object_ and releases it when the method returns. The lock release occurs even if the return was caused by an uncaught exception. "
what exactly does this mean?
do synchronized methods acquire the monitors for objects of type: java.lang.reflection.Method
please consider this code:
public class Foo {
  private int counter = 0;
  public synchronized void incriment() { counter++; }
  public synchronized void decriment() { counter--; }
Foo f = new Foo();
Class[] sig = new Class[0];
Method m = f.getClass().getMethod("incriment", sig);
// ok. so "m" is the relevant method object.
f.incriment(); // <-- is the monitor for "m" ,
                      // or the monitor for "f", acquired?
.......my reading of the Concurrency Tutorial is that synchronized methods use the monitors of java.lang.reflection.Method objects?
and thus, Foo is not thread safe, right?
however, this simple change makes Foo thread-safe?
public class Foo {
  private volatile int counter = 0; // "volatile"
  public void incriment() { counter++; }
  public void decriment() { counter--; }
}thanks.
Edited by: kogose on Feb 23, 2009 7:13 PM

tensorfield wrote:
jverd wrote:
tensorfield wrote:
kogose wrote:
what exactly does this mean?It means you're complicating things.
If a method is synchronized, it is. You don't need to go beyond that. The method is synchronized.Not true. You have to know what it means for a method to be synchronized. Often people come in with the erroneous impression that it somehow prevents you from using or accessing the object in any other thread.It's very simple. If a synchronized method is called at the same time from many threads only one call will be executed at a time. The calls will be lined up and performed one after the other in sequence.
AND because synchronization is on a per object basis, when one synchronized method is being called from one thread, all synchronized methods of that same object are blocked for calling from other threads.
Simple as that.No, it's not that simple, and as stated, that is not correct. In particular, you didn't mention that for an instance method, all the various threads have to be trying to call instance methods on the same object in order for execution to be sequential.
You really can't understand Java's syncing without understanding how it relates to locks, and what it means for a method to be synchronized in terms of which lock it acquires.
Edited by: jverd on Feb 25, 2009 2:47 PM

Similar Messages

  • Intrinsic locks - static synchronized method

    I am trying to understand the "static synchronized threads" - by theory when such a thread is invoked, it has to obtain a intrinsic lock on all the static variables. I wrote a sample program, but it is not giving me the desired results.
    I have 3 threads, t1, t2, t3. t1 calls a static synchronized method crazy(), where i am using static int i. t2 and t3 calls a void function f2() and f3() which just prints i. Now i put a sleep in synchronized method crazy. I am expecting t1 to start and print i and go to sleep for 10 secs, release i and then t2 and t3 starts since crazy() holds an intrinsic lock on i. But the program calls t2 and t3 even if crazy puts the thread to sleep. What happend to the intrinsic lock on i ??
    class RunnableThread implements Runnable{
    static String i;
    void f2() {
    RunnableThread.i = "Two";
    System.out.println(RunnableThread.i);
    void f3() {
    this.i = "three";
    System.out.println(this.i);
    static synchronized void crazy() {
    try {
    i = "One";
    System.out.println(i);
    Thread.sleep(10000);
    System.out.println("Sleep done");
    catch (Exception e ) {
    e.printStackTrace();
    public void run() {
    System.out.println("Thread Name: " + Thread.currentThread().getName());
    if (Thread.currentThread().getName().equals("two"))
    f2();
    } else if (Thread.currentThread().getName().equals("three"))
    f3();
    else if (Thread.currentThread().getName().equals("one"))
    RunnableThread.crazy();
    public static void main(String args[]) {
    System.out.println("SOP from main");
    RunnableThread rt1 = new RunnableThread();
    RunnableThread rt2 = new RunnableThread();
    RunnableThread rt3 = new RunnableThread();
    Thread t1 = new Thread(rt1, "one");
    t1.start();
    Thread t2 = new Thread(rt2, "two");
    t2.start();
    Thread t3 = new Thread(rt3, "three");
    t3.start();

    lavanya.km wrote:
    I am trying to understand the "static synchronized threads"Never heard of it. You might want to clarify your terminology.
    - by theory when such a thread is invoked, it has to obtain a intrinsic lock on all the static variables. Nope. Doesn't happen.
    I wrote a sample program,Ah, I see. You're creating synchronized static methods. Those do not even come close to "obtaining an intrinsic lock on all the static variables," even if there were such a thing as an "intrinsic lock," which there isn't. A synchronized method is just shorthand for enclosing the entire body in a sync block. In the case of a non-static method, it syncs on the "this" object. In the case of a static method, it syncs on the Class object for the class where the method is declared.
    In no case does anything sync on "all the variables," static or not.

  • Synchronized method's block list implementation

    In an object with synchronized methods, the OS maintains the list of blocked objects waiting to enter synchronzied methods. For this reason, I'm guesing, the Java spec seems to state the selection of these blocked objects as "arbitrary."
    I am trying to determine that there is no risk of stavation in this blocked pool of threads. For example, a FIFO implementation of the blocked-object list would guarantee that all objects eventually entered their appropriate synchronized method.
    Does anyone know for certain what blocked object selection algorithm is present on a JVM running on a Win32 platform? On SunOS 5.6? I believe the former uses a priority-based, preemptive thread scheduling with a round-robin-style time quantum to prevent starvation. Not sure what the latter uses.
    Any ideas? Thanks!
    -Jeff Ishaq

    In an object with synchronized methods, the OS
    maintains the list of blocked objects waiting to enter
    synchronzied methods. For this reason, I'm guesing,
    the Java spec seems to state the selection of these
    blocked objects as "arbitrary."
    As a general rule, you can never depend on the underlying threading model. The trend is to use the native threading model but that is not guaranteed by the specification.
    I am trying to determine that there is no risk of
    stavation in this blocked pool of threads. For
    example, a FIFO implementation of the blocked-object
    list would guarantee that all objects eventually
    entered their appropriate synchronized method.
    When a thread attempts to acquire a lock, it only checks to see if another thread already holds the lock, and not if another thread is already waiting for the lock. Therefore you should always consider the possibility that starvation can occur.
    Does anyone know for certain what blocked object
    selection algorithm is present on a JVM running on a
    Win32 platform? On SunOS 5.6? I believe the former
    uses a priority-based, preemptive thread scheduling
    with a round-robin-style time quantum to prevent
    starvation. Not sure what the latter uses.
    Again, you should avoid depending on the native threading model because the specification does not guarantee that the java threading model is going to behave the same way.
    To guarantee that each thread can acquire the lock you will need to develop a lock that has a queue associated with it. When a thread attempts to acquire the lock it is placed in a queue waiting until it is the first element in the queue. When the thread releases the lock it removes itself from the queue and notifies the other threads that are waiting.
    When using a queued lock you will not necessarily need to use the synchronized keyword on the method or block since the lock will take care of synchronization when a thread attempts to acquire the lock.

  • Health Service in which the location monitoring object is contained is not available

    Hello,
    When i am trying to discover new machines I am getting this error:
    Health Service 'OPMGRRMS1.xxx.xxx.xxx.xxx' in which the location monitoring object is contained is not available
    All services have been restarted successfully without error... on the RMS Server.
    - System Center Data Access
    - System Center Management
    - System Center Management Configuration
    - System Event Notification Service
    but still having the error...
    Date: 10/27/2009 10:14:00 AM
    Application: System Center Operations Manager 2007 R2
    Application Version: 6.1.7221.0
    Severity: Error
    Message:
    Microsoft.EnterpriseManagement.Common.LocationMonitoringObjectNotAvailableException: Health Service 'OPMGRRMS1.ad.medctr.ucla.edu' in which the location monitoring object is contained is not available. Make sure that the computer hosting the Health Service is available and verify that the Health Service is running.
    at Microsoft.EnterpriseManagement.DataAbstractionLayer.SdkDataAbstractionLayer.HandleSubmitTaskIndigoExceptions(Exception ex)
    at Microsoft.EnterpriseManagement.DataAbstractionLayer.AdministrationOperations.LaunchDiscovery(Guid batchId, List`1 jobDefinitions)
    at Microsoft.EnterpriseManagement.Administration.ManagementServer.BeginExecuteWindowsDiscovery(IList`1 discoveryConfigurations, AsyncCallback callback, Object state)
    at Microsoft.EnterpriseManagement.Mom.Internal.UI.Administration.DiscoveryProgress.<>c__DisplayClass7.<SubmitTask>b__3(Object , ConsoleJobEventArgs )
    at Microsoft.EnterpriseManagement.Mom.Internal.UI.Console.ConsoleJobExceptionHandler.ExecuteJob(IComponent component, EventHandler`1 job, Object sender, ConsoleJobEventArgs args)
    DW works (Datawarehouse) I restarted the System Center Management successfully
    MS works (2nd Management Server) I restarted the System Center Management successfully
    ACS works (Audit Control Server) cannot access the reporting server but I restarted the System Center Management successfully
    RMS DB 48 % Free
    DW DB 18% Free
    ACS DB 13% Free
    I can ping the RMS Server what other test could I do?
    I removed the new items:
    Delete the six modules of Windows Failover Clustering Management Pack (SCOM Console > Administration > Management Packs > Right Click delete on it)
    Uninstall System Center Operations Manager 2007 R2 Authoring Resource Kit (Add/Remove Programs)
    Uninstall System Center Operations Manager 2007 R2 Authoring Console (Add/Remove Programs)
    Reboot the RMS Server
    SAME ERROR!!! 
    Any idea
    Thanks,
    Dom
    Altiris Support / System Center Configuration Manager Support

    Hi Marius,
    In the Operations Manager Log I have some errors:
    Log Name: Operations Manager
    Source: HealthService
    Date: 10/28/2009 10:15:06 PM
    Event ID: 4506
    Task Category: None
    Level: Error
    Keywords: Classic
    User: N/A
    Computer: OPMGRRMS1.ad.medctr.ucla.edu
    Description:
    Data was dropped due to too much outstanding data in rule "Microsoft.SQLServer.2008.LoginsPerSecCollection" running for instance "MSSQLSERVER" with id:"{24345584-0FD5-0FAB-2293-D4C82BEDB086}" in management group "SCOM-MED".
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
    <Provider Name="HealthService" />
    <EventID Qualifiers="49152">4506</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2009-10-29T05:15:06.000Z" />
    <EventRecordID>4126486</EventRecordID>
    <Channel>Operations Manager</Channel>
    <Computer>OPMGRRMS1.ad.medctr.ucla.edu</Computer>
    <Security />
    </System>
    <EventData>
    <Data>SCOM-MED</Data>
    <Data>Microsoft.SQLServer.2008.LoginsPerSecCollection</Data>
    <Data>MSSQLSERVER</Data>
    <Data>{24345584-0FD5-0FAB-2293-D4C82BEDB086}</Data>
    </EventData>
    </Event>
    Log Name: Operations Manager
    Source: HealthService
    Date: 10/28/2009 10:15:50 PM
    Event ID: 1107
    Task Category: Health Service
    Level: Error
    Keywords: Classic
    User: N/A
    Computer: OPMGRRMS1.ad.medctr.ucla.edu
    Description:
    Account for RunAs profile in workflow "Microsoft.SystemCenter.DataWarehouse.CollectEntityHealthStateChange", running for instance "OPMGRRMS1.ad.medctr.ucla.edu" with id:"{DF927679-EAC0-B8EC-F8CC-F0031A36AD4F}" is not defined. Workflow will not be loaded. Please associate an account with the profile. Management group "SCOM-MED"
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
    <Provider Name="HealthService" />
    <EventID Qualifiers="49152">1107</EventID>
    <Level>2</Level>
    <Task>1</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2009-10-29T05:15:50.000Z" />
    <EventRecordID>4126487</EventRecordID>
    <Channel>Operations Manager</Channel>
    <Computer>OPMGRRMS1.ad.medctr.ucla.edu</Computer>
    <Security />
    </System>
    <EventData>
    <Data>SCOM-MED</Data>
    <Data>{DF927679-EAC0-B8EC-F8CC-F0031A36AD4F}</Data>
    <Data>OPMGRRMS1.ad.medctr.ucla.edu</Data>
    <Data>Microsoft.SystemCenter.DataWarehouse.CollectEntityHealthStateChange</Data>
    </EventData>
    </Event>
    Log Name: Operations Manager
    Source: HealthService
    Date: 10/28/2009 10:15:50 PM
    Event ID: 1107
    Task Category: Health Service
    Level: Error
    Keywords: Classic
    User: N/A
    Computer: OPMGRRMS1.ad.medctr.ucla.edu
    Description:
    Account for RunAs profile in workflow "Microsoft.SystemCenter.DataWarehouse.CollectEventData", running for instance "OPMGRRMS1.ad.medctr.ucla.edu" with id:"{DF927679-EAC0-B8EC-F8CC-F0031A36AD4F}" is not defined. Workflow will not be loaded. Please associate an account with the profile. Management group "SCOM-MED"
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
    <Provider Name="HealthService" />
    <EventID Qualifiers="49152">1107</EventID>
    <Level>2</Level>
    <Task>1</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2009-10-29T05:15:50.000Z" />
    <EventRecordID>4126488</EventRecordID>
    <Channel>Operations Manager</Channel>
    <Computer>OPMGRRMS1.ad.medctr.ucla.edu</Computer>
    <Security />
    </System>
    <EventData>
    <Data>SCOM-MED</Data>
    <Data>{DF927679-EAC0-B8EC-F8CC-F0031A36AD4F}</Data>
    <Data>OPMGRRMS1.ad.medctr.ucla.edu</Data>
    <Data>Microsoft.SystemCenter.DataWarehouse.CollectEventData</Data>
    </EventData>
    </Event>
    Log Name: Operations Manager
    Source: HealthService
    Date: 10/28/2009 10:15:50 PM
    Event ID: 1107
    Task Category: Health Service
    Level: Error
    Keywords: Classic
    User: N/A
    Computer: OPMGRRMS1.ad.medctr.ucla.edu
    Description:
    Account for RunAs profile in workflow "Microsoft.SystemCenter.DataWarehouse.CollectPerformanceData", running for instance "OPMGRRMS1.ad.medctr.ucla.edu" with id:"{DF927679-EAC0-B8EC-F8CC-F0031A36AD4F}" is not defined. Workflow will not be loaded. Please associate an account with the profile. Management group "SCOM-MED"
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
    <Provider Name="HealthService" />
    <EventID Qualifiers="49152">1107</EventID>
    <Level>2</Level>
    <Task>1</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2009-10-29T05:15:50.000Z" />
    <EventRecordID>4126489</EventRecordID>
    <Channel>Operations Manager</Channel>
    <Computer>OPMGRRMS1.ad.medctr.ucla.edu</Computer>
    <Security />
    </System>
    <EventData>
    <Data>SCOM-MED</Data>
    <Data>{DF927679-EAC0-B8EC-F8CC-F0031A36AD4F}</Data>
    <Data>OPMGRRMS1.ad.medctr.ucla.edu</Data>
    <Data>Microsoft.SystemCenter.DataWarehouse.CollectPerformanceData</Data>
    </EventData>
    </Event>
    these errors are recurrent...
    the RMS is doing yoyo between Green as healthy and grayed out under Monitoring > Windows Computers or Administration > Device Management > Management Servers (2-3 minutes green then grayed out) there is no event in the Windows Event Log as System Center Management service remains running...
    This MP for the Data Warehouse Internal Library has been removed and restored two weeks agao with Premier Support as the RMS was already fleaky and doing gray-green...
    I have tried again but I will need to check again as it seems these errors are pointing to the Data Warehouse Library and not only the Data Warehouse Internal Library Management Pack. The main problem with this is that the Data Warehouse Library is [b]94[/b] Management Packs which depends on this Data Warehouse Library in our environment so if I need to remove this one it is almost a complete reinstallation of 50% of our MPs :(
    Heartbeat failures: The Heartbeat State view ( Health Service Watcher (Agent) - All) is giving me 10 Critical and 1 Warning
    [b]Any way to delete All MPs and restore them at once?[/b]
    I have an issue trying deleting "Notifications Internal Library":
    The User does not have sufficient permissions to perform the operation"
    I am using my own account which is supposed to have all accesses.
    I tried the hotfix 938510 but it does not seem to apply to SCOM R2
    Thanks
    Dom
    Altiris Support / System Center Configuration Manager Support

  • Use of 'static' keyword in synchronized methods. Does it ease concurrency?

    Friends,
    I have a query regarding the use of 'synchronized' keyword in a programme. This is mainly to check if there's any difference in the use of 'static' keyword for synchronized methods. By default we cannot call two synchronized methods from a programme at the same time. For example, in 'Program1', I am calling two methods, 'display()' and 'update()' both of them are synchronized and the flow is first, 'display()' is called and only when display method exits, it calls the 'update()' method.
    But, things seem different, when I added 'static' keyword for 'update()' method as can be seen from 'Program2'. Here, instead of waiting for 'display()' method to finish, 'update()' method is called during the execution of 'display()' method. You can check the output to see the difference.
    Does it mean, 'static' keyword has anything to do with synchronizaton?
    Appreciate your valuable comments.
    1. Program1
    public class SynchTest {
         public synchronized void display() {
              try {
                   System.out.println("start display:");
                   Thread.sleep(7000);
                   System.out.println("end display:");
              } catch (InterruptedException e) {
                   e.printStackTrace();
         public synchronized void update() {
              try {
                   System.out.println("start update:");
                   Thread.sleep(2000);
                   System.out.println("end update:");
              } catch (InterruptedException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              System.out.println("Synchronized methods test:");
              final SynchTest synchtest = new SynchTest();
              new Thread(new Runnable() {
                   public void run() {
                        synchtest.display();
              }).start();
              new Thread(new Runnable() {
                   public void run() {
                        synchtest.update();
              }).start();
    Output:
    Synchronized methods test:
    start display:
    end display:
    start update:
    end update:
    2. Program2
    package camel.java.thread;
    public class SynchTest {
         public synchronized void display() {
              try {
                   System.out.println("start display:");
                   Thread.sleep(7000);
                   System.out.println("end display:");
              } catch (InterruptedException e) {
                   e.printStackTrace();
         public static synchronized void update() {
              try {
                   System.out.println("start update:");
                   Thread.sleep(2000);
                   System.out.println("end update:");
              } catch (InterruptedException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              System.out.println("Synchronized methods test:");
              final SynchTest synchtest = new SynchTest();
              new Thread(new Runnable() {
                   public void run() {
                        synchtest.display();
              }).start();
              new Thread(new Runnable() {
                   public void run() {
                        synchtest.update();
              }).start();
    Output:
    Synchronized methods test:
    start display:
    start update:end update:
    end display:

    the synchronized method obtain the lock from the current instance while static synchronized method obtain the lock from the class
    Below is some code for u to have better understanding
    package facado.collab;
    public class TestSync {
         public synchronized void add() {
              System.out.println("TestSync.add()");
              try {
                   Thread.sleep(2000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              System.out.println("TestSync.add() - end");          
         public synchronized void update() {
              System.out.println("TestSync.update()");
              try {
                   Thread.sleep(2000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              System.out.println("TestSync.update() - end");          
         public static synchronized void staticAdd() {
              System.out.println("TestSync.staticAdd()");
              try {
                   Thread.sleep(2000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              System.out.println("TestSync.staticAdd() - end");
         public static synchronized void staticUpdate() {
              System.out.println("TestSync.staticUpdate()");
              try {
                   Thread.sleep(2000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              System.out.println("TestSync.staticUpdate() - end");
         public static void main(String[] args) {
              final TestSync sync1 = new TestSync();
              final TestSync sync2 = new TestSync();
              new Thread(new Runnable(){
                   public void run() {
                        sync1.add();
              }).start();
              new Thread(new Runnable(){
                   public void run() {
                        sync2.update();
              }).start();
              try {
                   Thread.sleep(3000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              new Thread(new Runnable(){
                   public void run() {
                        sync1.staticAdd();
              }).start();
              new Thread(new Runnable(){
                   public void run() {
                        sync2.staticUpdate();
              }).start();
    }

  • Multiple static synchronized methods locking the same object ?

    If I have multiple static synchronized methods in a class will all the methods lock on the same (Class) object ? I guess the answer to this would be yes. In that case is it possible achieve synchronization without an object ie code level synchronization ? If yes, how ?

    If I have multiple static synchronized methods in a
    class will all the methods lock on the same (Class)
    object ? I guess the answer to this would be yes. In
    that case is it possible achieve synchronization
    without an object ie code level synchronization ? If
    yes, how ?There is nothing special about static synchronized methods vs. any other synchronization. It's just shorthand for syncing on the Class object for that class. The effects of synchronization are identical no matter what you sync on.
    There's no way to achieve synchronization without an object. Synchronizing always obtains an object's lock. In the case of static synced methods, the object whose lock we obtain is the Class object for that class. As far as syncing goes, it's just another object.
    There is no such thing as "code level synchronization" vs. any other kind. All syncing occurs in your Java code over blocks of code. For synced methods, those blocks are the entire respective method bodies.
    Having said all that, I have no idea what you're really after or what you're trying to achieve.

  • Which object called the method

    Suppose there is a class A which has three objects a1,a2,a3 and a method m. Now I'd like to know which particular object has called the method m.

    >
    which particular object has called the method
    What class called my method
    http://developer.java.sun.com/developer/qow/archive/104
    a.The advice in the posted link is unreliable as the format of printStackTrace() is not standardized. A more reliable way to find out the calling class is to use SecurityManager.getClassContext() or Throwable.getStackTrace() [in JDK 1.4+].
    However, it is not clear whether the original poster wanted to know the calling class or the calling object. In the latter case there is no easy way except for modify the signature of method m to accept the reference to the calling object.
    Vlad.

  • Synchronized method in a java class used by many interfaces

    My interface (idoc to file) is using a java class, which has one method that reads a table from a central database and after doing some calculations updates it.
    (The interface instantiate the class inside a user-defined function and calls the method there.)
    The problem is that if somebody sends 100 idocs at the same time, there can be a “dirty read”, I mean, a read just before other interface updates the table.
    We want the following:
    Interface 1:
    -          Read counter from the table (counter = 5 )
    -          Increment counter (counter = 6)
    -          Update table with that counter (table with counter = 6)
    Interface 2:
    -          Read counter from the table (counter = 6 )
    -          Increment counter (counter = 7)
    -          Update table with that counter (table with counter = 7)
    RESULT: The table has the counter = 7
    But what is happening is the following:
    -          Interface 1 reads (counter = 5)
    -          Interface 2 reads (counter = 5)
    -          Interface 1 increments counter (counter = 6)
    -          Interface 2 increments counter (counter = 6)
    -          Interface 1 updates table (table with counter = 6)
    -          Interface 2 updates table (table with counter = 6)
    RESULT: The table has the counter = 6 (WRONG)
    I made the method synchronized. What I was expecting was that only one interface (i1) could enter the method (read the table and update it) while other interfaces running at the same time would have to wait until i1 finished that method.
    My first test indicates that's not happening. Can anybody help me to find a solution?

    Hi Bhavesh,
    If the QOS is EOIO this means that the integration engine manage the call to the mapping program (and all the other blocks) inside an "internal" synchronized method.
    So this means that in this case you do not need to manage the queued access (synchronization) inside your custom java code because it is already enveloped in a queued block by XI.
    The problem that Jorge had can be easily reproduced using the sample code that follows:
    <b>class Synch Object</b>
    import java.util.Date;
    public class SynchObject {
         String strName;
         public SynchObject(String strName){
              this.strName = strName;
         public synchronized void syncWrite(String strCaller) throws InterruptedException{
              Date now;
              now = new Date();
              System.out.println("-- " + now.toLocaleString() + " " + strCaller + " entering syncWrite of " + strName);
              System.out.flush();
              Thread.sleep(1000);
              now = new Date();
              System.out.println("-- " + now.toLocaleString() + " syncWrite of " + strName + " called by " + strCaller );
              System.out.flush();
              Thread.sleep(1000);
              now = new Date();
              System.out.println("-- " + now.toLocaleString() + " " + strCaller + " leaving syncWrite of " + strName);
              System.out.println("");
              System.out.flush();
    <b>class Caller</b>
    public class Caller implements Runnable {
         String strName;
         SynchObject target;
         int intMax;
         public Caller(String strName, SynchObject target, int intMax) {
              this.strName = strName;
              this.target = target;
              this.intMax = intMax;
         public void run() {
              for(int i=0; i<intMax;i++)
                   try {
                        target.syncWrite(strName);
                   } catch (InterruptedException e) {
                        e.printStackTrace();
    <b>class Workbench</b>
    public class Workbench {
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              SynchObject sObj1 = new SynchObject("syncObj1");
              SynchObject sObj2 = new SynchObject("syncObj2");
              Caller c1 = new Caller("caller1",sObj1,2);
              Caller c2 = new Caller("caller2",sObj1,2); '[*CHANGE*]
              Thread ct1 = new Thread(c1);
              Thread ct2 = new Thread(c2);
              ct1.start();
              ct2.start();
    Run the workbench class to see what happen when setting QOS EOIO (the synch object is the same).
    To see instead what happen now (missing synchronization) you have to change in Workbench class the statement
    Caller c2 = new Caller("caller2",sObj1,2); '[*CHANGE*]
    with
    Caller c2 = new Caller("caller2",sObj2,2); '[*CHANGE*]
    The reason is that every instance of the mapping program declare a new instance of the "Synchronized object" so the calls are synchronized inside the same mapping program but not between several mapping program.
    Hope this give you a better idea on this problems with java synchronization, but if you have further doubts (I know it's a little bit tricky ) feel free to ask.
    Kind Regards,
    Sergio

  • Object instance 1200 does not exist (while executing task SWUS)

    hello all,
    i have created a workflow class and two methods (constructor, display) and 1 attribute PLANT (instance,public) in it.
    i am using this class and display method in task t code PFTC.
    While executing this task from SWUS , i am getting this error.Object instance 1000 does not exist.
    As i was going through this blog. i have created everything exactly just like it is mentioned there.
    But still i am getting this error. please guide me to detect where i am mistaken.
    http://scn.sap.com/community/bpm/business-workflow/blog/2006/07/25/using-abap-oo-methods-in-workflow-tasks
    this is class screen-shot and error i am facing while executing the task.
    The methods which are implemented using the interface are emtpy(don't contain any source code lines).

    sorry i forgot to mention that input value 1000 does exist in our system.
    i have also tried F4 help. it is showing all existing plants in our system, but still it is not accepting values select from f4 help.
    Also to add information,
    I have executed class using F8 option in class builder, and it is working perfect.
    source code of display method.(i am trying to view plant in display method just like in blog).
    method DISPLAY.
    break-point.
       data: ls_vt001w type v_t001w.
       CLEAR ls_vT001W.
       ls_VT001W-MANDT = SY-MANDT.
       ls_VT001W-WERKS = me->PLANT.
       CALL FUNCTION 'VIEW_MAINTENANCE_SINGLE_ENTRY'
         EXPORTING
           ACTION    = 'SHOW'
           VIEW_NAME = 'V_T001W'
         CHANGING
           ENTRY     = ls_vT001W.
    endmethod.

  • Calling static synchronized method in the constructor

    Is it ok to do so ?
    (calling a static synchronized method from the constructor of the same class)
    Please advise vis-a-vis pros and cons.
    regards,
    s.giri

    I would take a different take here. Sure you can do it but there are some ramifications from a best practices perspective. f you think of a class as a proper object, then making a method static or not is simple. the static variables and methods belong to the class while the non-static variables and methods belong to the instance.
    a method should be bound to the class (made static) if the method operates on the class's static variables (modifies the class's state). an instance object should not directly modify the state of the class.
    a method should be bound to the instance (made non-static) if it operates on the instance's (non-static) variables.
    you should not modify the state of the class object (the static variables) within the instance (non-static) method - rather, relegate that to the class's methods.
    although it is permitted, i do not access the static methods through an instance object. i only access static methods through the class object for clarity.
    and since the instance variables are not part of the class object itself, the language cannot and does not allow access to non-static variables and methods through the class object's methods.

  • While doing LSMW standard method for Customer master creation..

    while doing LSMW standard method for Customer master creation.....
    In 13th step I am getting this king of error
    FB012                    Session 1 : Special character for 'empty field' is /
    FB007                    Session 1 session name ZPROJ was opened
    FB109                    Trans. 1 : Transaction xd01 is not supported
    FB016                    ... Last header record ...
    FB014                    ... BKN00-STYPE 1
    FB014                    ... BKN00-TCODE xd01
    FB014                    ... BKN00-KUNNR
    FB014                    ... BKN00-BUKRS
    FB014                    ... BKN00-VKORG A1
    FB014                    ... BKN00-VTWEG 00
    FB014                    ... BKN00-SPART 0
    FB014                    ... BKN00-KTOKD
    FB014                    ... BKN00-KKBER BP01
    FB013                    ....Editing was terminated
    Can anyone help how to solve this?

    Hello TJK,
    <b>FB012 Session 1 : Special character for 'empty field' is /</b>
    This is the special function in LSMW, for empty field system will put / sign automatically, so you need not to worry about that.
    <b>FB007 Session 1 session name ZPROJ was opened</b> It is opening session ZPROJ which is your project name/object name.
    <b>FB109 Trans. 1 : Transaction xd01 is not supported</b>
    Check out your field mapping and conversion rule for object.
    <b>FB013 ....Editing was terminated</b>
    It is not finding proper field mapping rule / file inputs so the sytem terminates the LSMW object.
    Check your field mapping and conversion rule, check your source fields, save the file in tab delimited format.
    Hope this helps.
    Regards
    Arif Mansuri

  • Impact Analysis: How to trace which objects and tables used in a report?

    Impact Analysis: How to trace which Webi objects and tables used in a report?
    Currently, our company have been using BO Webi as our ad-hoc and reporting tool for over a year now.  Past several months, we've been pushing our power users to develop their own report, and started to notice that we loss track off which data (tables, columns, ... , BO objects) being used where and by whom.   The BI team now spend more time tracing through reports manually, instead of designing Universe.
    After consulted with our local  SAP  technical sale, they said the only solution is to buy BO's ETL (Data Integration) and
    Metadata Management tool, which price starting from $300K per CPU.  I suppose that is NOT the right solution; however, we have not found one yet.  Some executives believe Cognos (now by IBM) would provide a better BI solution as we scale.
    If anyone know, please provide (1) Impact Analysis method: How to trace which Webi objects and tables used in a report? and (2) Does Cognos provide better impact analysis method without a heavy spending?
    Thank you very much,
    Ed
    Edited by: EdPC-SCB on Sep 8, 2009 3:56 PM

    EdPC-SCB,
    have you tried enabling auditing?
    - Yes, audit log only shows user's activities which isn't useful for us. Please let us know any audit log that might be helpful .
    For most of the servers listed in the CMC there is an "Audit" tab.  I'd say if you have the disk space in your database for Auditor available, then if in doubt turn it on (at least for a while) to see if it exposes what you are seeking to find out --that'd be the quickest way.  The documentation (xir2_bip_auditor_en.pdf) doesn't offer much in helping you to see a correlation between ticking on an Audit option in a Server and how it will populate in the Auditor DB -- most of us just hunt and peck until we get what we want.  Once you have the good stuff in each of the Servers ticked on you'll be able to track down which report recieves which object.  To help youself out initially, you should run every report that you can find so Auditor will get seeded.
    thanks,
    John

  • Need of more than one synchronized methods

    Inside my run method I'm calling a synchronized method which in turn calls other synchronized methods of the same and another class.
    Now if the top level method is synchronized, does the need to make other methods synchronized still remain ?
    Won't the other threads wait till the thread using the top level synchronized method returns.
    Vik

    Well, if you can be sure that the second method is not going to be called some other way except within that first synchronized method, then no it's not needed.

  • What is a lock in a synchronized method ??

    Greetings,
    I have a synchronized reset method whose job is to reset every variable i am using in that class.. its a synchronized method so when i am doing the reset stuff, no other method in that class can update that variable. But someone told me i need to also put lock inside the reset method and check for the lock everywhere where i update those variables ( So that variable doesn't update itself and lose its value as reset would be resetting that variable.) How do i lock all these variables in that reset method and how do i check for the lock where i would be updating that variable.
    Example: Psedo code
    class {
    int a =0;
    int b = 0;
    method update {
    a = 5;
    method update1{
    b = 6;
    synchronized method reset{
    a =0;
    b = 0;

    javanewbie83 wrote:
    Greetings,
    I have a synchronized reset method whose job is to reset every variable i am using in that class.. its a synchronized method so when i am doing the reset stuff, no other method in that class can update that variable. But someone told me i need to also put lock inside the reset method and check for the lock everywhere where i update those variables ( So that variable doesn't update itself and lose its value as reset would be resetting that variable.) How do i lock all these variables in that reset method and how do i check for the lock where i would be updating that variable.You don't need to "check" for the lock. When you have a synchronized block or method, the synhcronized keyword tells the VM to stop executing that thread until it can attain the object's lock, then give the object's lock to that thread, and then take it back when the thread leaves the synchronized block (or calls wait()). It's all automatic.
    Note that you'll need to synchronize not only write access to the variable(s) in question, but read access also, in order to ensure that reader threads see the values written by writers.

  • Which version of jsdk does 9i support

    Hi
    I am trying to compile a servlet which has calls to methods like
    setAttribute(String, object) and getRequestDispatcher(String )
    But it gives this error - NO such method supported
    What do i have to do so that my ser let runs on oracle 9I with
    these method calls
    Rgds

    Audition CS6 supports plugins up to VST 3. This does not include VSTi (virtual instrument) plugins.
    Which version of VST does CS6 support?.

Maybe you are looking for

  • ITunes not using the defined proxy setting

    iTunes 10.0.1 on MacOS X 10.6.4 isn't correctly using the system proxy setting defined through:<pre>System Preferences- Network Advanced- Proxies Web proxy (HTTP) Web Proxy Server myproxy.my_company.mycountry : 3128</pre> For example, when selecting:

  • Workspace 11.1.1.3 and HFM cannot open apps

    Hi, I have an issue where i cannot open any apps in workspace 11.1.1.3. I checked and all services for workspace and HFM are running with IIS as well. I can open the app in the client, but on the Web, i cannot. I did a reconfiguration and that also d

  • Should I buy a Zen Tou

    I'm thinking of getting a refund for my 30 GB zen xtra because it doesn't play audiobooks with the proper length and buying a Zen Touch. Is this audiobook problem just with Zen Xtra or with all Creative players? Does anybody know of this problem disa

  • Is it possible to prevent the admin hack on a mack

    Hi any of youse know that there is an hack for macs where users can easily delete a setup file on the mac and reboot it so they can  setup another mac admin account Im wondering how to prevent this from occuring

  • Crystal Report on Universe with MySQL ODBC

    Hi I created a report with Crystal reports by using a Universe based on MySQL ODBC. In my local (Windows XP) installed Report Designer everything is running fine. I'm also able to publish this report to my BOE, based on RHEL. If I will refresh my rep