Atomic execution of multiple methods

Is it a flawed idea to try to execute a sequence of methods atomically in the following way?
synchronized(obj) {
obj.method1();
obj.method2();
Even if the object is thread-safe, it can still have methods that are not declared synchronized (e.g. because they involve a single atomic read/write operation). So these methods are not blocked by the synchronized block.
Is it better to consider the object's lock something internal to the object and should not be manipulated outside the object's implementation? In another word, is it better to rely on an external lock (i.e. an external object created solely for the purpose of locking) to achieve atomicity? Obviously, it's harder to make sure all invocations of method1 and method2 are done while holding this lock.

A thread will not block unless it synchronizes on a
"locked" object. If an object is "locked" and a
different thread enters one of its unsynchronized
methods it will not block.If an object is locked it will not allow another thread to access it's unsynchronized method.
Here is an example of locking an object and trying to access an unsychronized method with another thread which cannot be done until the synch block has finished.
public class Test3 extends Thread
    Test2 t2;
    /** Creates a new instance of Test3 */
    public Test3(Test2 t2Instance)
        t2 = t2Instance;
    public void run()
       // this is my seperate thread which calls a unsynchronized method
       // but it won't call it until after the synch block is through
       t2.unsynchronizedMethod();
       System.out.println("Called the unsych method using another thread.");
public class Test2
    /** Creates a new instance of Test2 */
    public Test2(int maxIndex)
        synchronized( this )
            // loop for 100 times to deminstrate the synch block
            for(int i = 0; i < maxIndex; i++)
                System.out.println("In synch block; count is " + i);               
    public void unsynchronizedMethod()
        System.out.println("Accessed unsynchronized method");
public class Test1
    /** Creates a new instance of Test1 */
    public static void main(String[] args)
        Test2 t2 = new Test2(10000);
        Test3 t3 = new Test3(t2);
        t3.start();
        t2.unsynchronizedMethod();
}The thread has to wait until the synch block is through before it can access the unsynchronized method of the locked object.

Similar Messages

  • Call Webservice URL with multiple methods in PI 7.0

    Dear Gurus,
    I have the following requirement:
    I need to make multiple calls to a same webservice (URL) which have multiple methods on its WSDL. I know it is possible in PI 7.1. But is it possible in PI 7.0?
    I have already designed and configured the scenarios and generated ABAP Proxy. When I call the endpoint without specifyng the method I got the following message:
      <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Inbound Message
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Category>XIAdapterFramework</SAP:Category>
      <SAP:Code area="MESSAGE">GENERAL</SAP:Code>
      <SAP:P1 />
      <SAP:P2 />
      <SAP:P3 />
      <SAP:P4 />
      <SAP:AdditionalText>com.sap.aii.af.ra.ms.api.DeliveryException: SOAP: response message contains an error XIAdapter/PARSING/ADAPTER.SOAP_EXCEPTION - soap fault: Endpoint {http://mywebserviceurl.com} does not contain operation meta data for: {http://mynamespace}MyMessageInterface</SAP:AdditionalText>
      <SAP:ApplicationFaultMessage namespace="" />
      <SAP:Stack />
      <SAP:Retry>M</SAP:Retry>
      </SAP:Error>
    Please somebody could help me to solve this issue?
    Thank you in advance.
    Fabio Purcino

    >>. But is it possible in PI 7.0?
    Just few cents..
    Test using SOAPUI or  XMLSPY and use that same WSDL URL in the target URL of Communication channel. Just to make sure you use the right endpoint.
    or
    You can specify the method name as  soap action dynamically using udf in mapping and see how it behaves.

  • Multiple methods

    can multiple methods be called like this?
    Whatever class = new Whatever();
    class.method1().method2().method3(param);

    can multiple methods be called like this?
    Whatever class = new Whatever();
    class.method1().method2().method3(param);Why don't you do this?
    class.method1(param);
    public method1(param){
    class.method2(param);
    public method2(param){
    class.method3(param);

  • Parallel execution of multiple test cases.

    Does flex unit 4.x version supports for parallel execution of multiple test cases?
    Any help will be greatly appreciated.

    No.
    Flash Player and AIR are single-threaded virtual machines. The only parallel execution one could do is during asynchronous tests, but we do not support that presently for a variety of reasons.
    Mike

  • OO ALV hotspot creation not working with Multiple Methods.

    Hi,
    I create a Test Report for Hotspot creation - It works. Code is  as -->
    class my_event_handler definition.
      public section.
      methods :
      handle_hotspot_click for event hotspot_click of cl_gui_alv_grid importing e_row.
      endclass.
      class my_event_handler implementation.
        method handle_double_click.
          read table itab index e_row-index into wa.
          if sy-subrc = 0.
           set PARAMETER ID 'ANR' FIELD order
    call transaction IW33.         
    endif.
      endclass.
    BUT - When I take multiple methods in PUBLIC SECTION. & Call it from START-OF-SELECTION the HotSpot is NOT WORKING
    CLASS get_details DEFINITION.
      PUBLIC SECTION.
        METHODS:  data_gathering,
                  display_alv.
                  handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row .
      PRIVATE SECTION.
        CLASS-METHODS: get_data,
                       merge_data,
                       set_header IMPORTING er_table TYPE REF TO cl_salv_table,
                       set_coloum IMPORTING pr_columns TYPE REF TO cl_salv_columns_table.
    ENDCLASS.       
    CLASS IMPLEMENTATION - IS SAME AS ABOVE.
    START-OF-SELECTION.
      CREATE OBJECT lr_details.
      lr_details->data_gathering( ).
      IF gi_final IS NOT INITIAL.
        lr_details->display_alv( ).
    *    lr_details->handle_hotspot_click( EXPORTING row = ?  ).  " What to take?
      ELSE.
        MESSAGE 'No Data for the Selection Critaria' TYPE 'S' DISPLAY LIKE 'E'.
      ENDIF.
    How get Hotspot in this Case, Do I need to take the Method in START-OF-SELECTION ?
    if YES - then what to Export ? If NO - then how to create Hotspot in this case?

    Thanks Neil. Now it's working.
    For this One line clue - I really searched a lot.
    Thank you so much.
    If checking this link For Reference -->
    Search 'SET HANDLER' in Google for sample programs.
    * Before Class Defination
    CLASS get_details DEFINITION DEFERRED.
    DATA: event_receiver1  TYPE REF TO get_details,
    * At the End of Method display_alv (Check question for Methods)
    CREATE OBJECT event_receiver1.
    SET HANDLER event_receiver1->handle_hotspot_click FOR ALL INSTANCES.

  • SSRS Execution Service Render Method stopped working

    Hello SSRS Profis!
    I'm having the following Problem:
    I was trying to integrate SSRS in my Company-Software, and until today it went quite good:
    Its an ASPMVC 5 project with WCF-Services, and in these i had methods to render reports with the help of the ReportExecution - Webservice (2005), the Version of the MSSQL Server we use is 2008R2, reports use stored procedures as data sets.
    Everything worked fine, i could render all my reports in the services, gave the result back to the Frontendprojects to present it there, it worked fast and properly.
    Until today: For some reason, the call of the ReportExection.Render() - Method gives no more results back.
    Debugging shows me that it works approx. the same time as it did before for every report, but the result now is only "null" for every report i integrated until now:
    Here is the code I use to execute the service (for network credentials i use a user with administrator privilegue who can access all the reports (tested in private session), Parameter constructio also should work properly because it did before, same
    for the Report path...
    Any Ideas would be helpful!
    private byte[] getPDFFromReport(string ReportPath, Dictionary<string, string> parameterDicitionary)
    ReportExecutionService rs = new ReportExecutionService();
    // private method to set a user with enough permissions
    rs.Credentials = SetServiceAccount();
    // Render arguments
    byte[] result = null;
    string reportPath = ReportPath;
    string format = "PDF";
    string historyID = null;
    string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
    // Prepare report parameter.// mapping Parameters, gives back ReportExecution.ParamaterValue Array, still works as it should
    ParameterValue[] parameters = SetReportParameters(reportPath, parameterDicitionary); DataSourceCredentials[] credentials = null;
    string showHideToggle = null;
    string encoding;
    string mimeType;
    string extension;
    Warning[] warnings = null;
    ParameterValue[] reportHistoryParameters = null;
    string[] streamIDs = null;
    ExecutionInfo execInfo = new ExecutionInfo();
    ExecutionHeader execHeader = new ExecutionHeader();
    rs.ExecutionHeaderValue = execHeader;
    execInfo = rs.LoadReport(reportPath, historyID);
    rs.SetExecutionParameters(parameters, "de-de");
    // rs.Timeout = 300000;
    String SessionId = rs.ExecutionHeaderValue.ExecutionID;
    Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);
    try
    result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
    execInfo = rs.GetExecutionInfo();
    Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);
    catch (SoapException e)
    Console.WriteLine(e.Detail.OuterXml);
    // Write the contents of the report to an MHTML file.
    return result;
    Edit:
    I tested the methods with the same user in an WindowsForms Project and got a result. In a former Version, it also still works. I changed nothing since the last deploy in this methods, so can't imagine why it suddenly stopped working....

    Found the solution!
    After checking team-foundation-changelogs of the last checkins, it turned out that somehow automatically some value in the reference.cs of the reportexecution - webservice was changed from:
            [return: System.Xml.Serialization.XmlElementAttribute("Result", DataType="base64Binary")]
    to
            [return: System.Xml.Serialization.XmlElementAttribute("Value", DataType="base64Binary")]
    After deleting and readding the webreference to the Project, it worked again.
    The next Thing to Research for me is how it can be, that this value automatically changes. Possibly because of different Versions of VS in the dev-Team.. (Ultimate and premium) In any case, this issue is solved, thank you for reading :)

  • Multiple method signatures in an MBean

    The text formatting seems to be broken on this site. Sorry for the mass of text!
    I have an MBean containing some utility functions used within a custom authenticator. At the moment, there all use a single data source, but I need to extend them to use multiple datasources. I also need to maintain backwards compatability with the original system.
    I have therefore modififed the xml bean descriptor file and Impl java class by duplicating all the methods, adding a dataSource ID param, as follows:
    I started with this method descriptor:
    <pre>
    <MBeanOperation
    Name = "getMaintenanceMode"
    ReturnType = "boolean"
    Description = "Whatever"
    >
    <MBeanException>javax.management.MBeanException</MBeanException>
    <MBeanException>weblogic.management.utils.NotFoundException</MBeanException>
    </MBeanOperation>
    </pre>
    and impl:
    <pre>
    public boolean getMaintenanceMode() throws MBeanException , javax.management.MBeanException, weblogic.management.utils.NotFoundException
    </pre>
    and have now added this :
    <pre>
    <MBeanOperation
    Name = "getMaintenanceMode"
    ReturnType = "boolean"
    Description = "Whatever"
    >
    <MBeanOperationArg Name = "dataSourceId" Type = "int"
    Description = "Data Source ID"
    />
    <MBeanException>javax.management.MBeanException</MBeanException>
    <MBeanException>weblogic.management.utils.NotFoundException</MBeanException>
    </MBeanOperation>
    </pre>
    and
    <pre>
    public boolean getMaintenanceMode(int dataSourceId) throws MBeanException , javax.management.MBeanException, weblogic.management.utils.NotFoundException
    </pre>
    With these code changes in place, the MBean builds correctly, using the MBeanMaker, however WLS(814) falls over on startup with the exception:
    <pre>
    javax.management.JMRuntimeException: Two operations with the same name, "getMaintenanceMode", in MBean type: com.aol.universal.security.tools.DashboardUserTools
    at weblogic.management.commo.ModelMBeanTypeMBean.getExpandedMBeanInstanceInfo(ModelMBeanTypeMBean.java:1092)
    at weblogic.management.commo.ModelMBeanTypeMBean.<init>(ModelMBeanTypeMBean.java:250)
    at sun.reflect.GeneratedConstructorAccessor3.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
    at com.sun.management.jmx.MBeanServerImpl.internal_instantiate(MBeanServerImpl.java:2232)
    at com.sun.management.jmx.MBeanServerImpl.createMBean(MBeanServerImpl.java:763)
    at weblogic.management.internal.RemoteMBeanServerImpl.createMBean(RemoteMBeanServerImpl.java:897)
    at javax.management.loading.MLet.getMBeansFromURL(MLet.java:542)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1633)
    at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1528)
    at weblogic.management.internal.RemoteMBeanServerImpl.private_invoke(RemoteMBeanServerImpl.java:988)
    at weblogic.management.internal.RemoteMBeanServerImpl.invoke(RemoteMBeanServerImpl.java:946)
    at weblogic.management.commo.Commo.initTypesAtLocation(Commo.java:1409)
    at weblogic.management.commo.Commo.initTypes(Commo.java:552)
    at weblogic.management.commo.Commo.initTypes(Commo.java:534)
    at weblogic.management.AdminServerAdmin.initializeCommo(AdminServerAdmin.java:656)
    at weblogic.management.AdminServerAdmin.initializeRepository(AdminServerAdmin.java:874)
    at weblogic.management.AdminServerAdmin.initialize(AdminServerAdmin.java:267)
    at weblogic.t3.srvr.T3Srvr.initializeHere(T3Srvr.java:771)
    at weblogic.t3.srvr.T3Srvr.initialize(T3Srvr.java:670)
    at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:344)
    at weblogic.Server.main(Server.java:32)
    </pre>
    Granted there <i>are</i> two methods with the same name, but they have different signatures, so they are <i>different</i> methods! Its just simple OO method overloading, after all!
    Has anyone run into this in, too? Is there a solution?
    cheers
    Paul

    Hi,
    I doubt that the addition of a second signature actually invalidates (the red X icon) the first signature, but rather it shows the signature as Valid with Changes (the pen & yellow triangle icon). Technically, that is the correct signature status, but because it caused so much confusion, beginning with version 9, we've changed the user interface and stopped indicating changes to the PDF if the only change is a subsequent signature.
    If on the other hand you are getting the red X for the first signature please let me know as I'd be curious to see the file.
    Steve

  • How prevent simultaneous execution of multiple button threads?

    My AS 3 program has multiple buttons. Users can select one and then immediately select another and this causes 2 threads that collide.  Once one button is executing, I want the other buttons to ignore clicks.
    I've tried using a lock:Boolean to indicate a button is being processed.  Each button checks lock.  My logic is such that when the AS 3 processor detects a locked condition, it abandons execution of that button.  However, surprisingly, it abandons execution only termporarily ... once the the boolean is unlocked, AS 3 comes back and executes the button.
    The problems are twofold:  1)  the first time the 2nd button attempts to execute (by checking lock), when it returns (from checking lock) and attempts to pick up processing where it left off, it seems to forget where it was and does not utlimately complete its task(s); possibly variables have been altered, it is difficult to say.  That is, AS 3 is unable to successfully pickup where it left off on the first button.
    2) the second problem is that AS 3 incorrectly returns to button 2 after the lock condition is cleared.  It persists and will execute that button.
    Can anyone tell me how once one button is selected, the others can be locked out and won't execute??  Multiple threads from these buttons is a problem.
    Thanks in advance.
    Steve @ U Iowa

    dmennenoh - OK.  The downside to that type of solution is that each button has to "know" which other buttons are on the stage at that time, but, yes, that should work.  Do you think turning their visibility off would or would not be as effective as removing the event listeners?  I'm thinking turning visiblity on or off is simpler and simpler to manage.  Thanks for your help.

  • Parallel execution of multiple scripts

    Hi All,
    I understand that by using parallel hint we can achieve parallel execution of the queries(insert/update/delete).
    For my today's question I would like know if Parallelism can be achieved for the following scenario.
    I have a script with an insert-select statement and multiple merge statements and few update statements all on the same table.
    I have to run this script 12 times on the same table, once for each month of the year.
    Currently we run for Jan (where record_date = '201001') commit it, and then run for Feb, and so on.
    Can all the 12 month be run in parallel. One way I can think of is create 12 different scripts and kick them of by opening 12 different SQL Plus sessions (all on the same table).
    Is there a better way of doing this ?
    Note: each month data will not effect the other other month data.
    Regards,
    Aj

    Creating 12 different scripts would be a sub-optimal solution, and a maintenance nightmare. Creating 1 parametrized script and call that 12 times with different parameters would be slightly better.
    Creating 1 stored procedure with parameters, and run that procedure in the scheduler 12 times would still be better, as everything runs at the server side only.
    Your description is deliberately vague, so the possibility of deadlock can not be excluded.
    Sybrand Bakker
    Senior Oracle DBA

  • Double execution of actionListener method, normal behavior

    Hi,
    I don't understand this behavior i have a commandButton in my JSP
    <h:commandButton value="testActionListener" actionListener="#{LoginBean.actionListener}" immediate="true" />When I click on this button, the associated code (my actionListener method in my bean) is executed two times.
    In my opinion if the scope of my bean is "request" the execution would have to be the constructor then my method actionListener.
    Why do this method is executed two times after the constructor ? Is it the normal behavior ?
    Thanks
    Edited by: Antony97 on Dec 13, 2008 8:03 AM

    hello
    try this link
    http://www.javabeat.net/tips/67-how-to-implement-actionlistener-factionlist.html
    initally i got the same problem
    write seperate bean and actionlistener. as the link suggest your problem is solved

  • Order of execution of named method user properties and server script

    Dear All,
    If for a Custom method on an applet, we have scripts in WebApplet_preinvokemethod and WebApplet_invokemethod and also for the same Custom method we have applet Named Method user properties and BC Named Method user properties, what will be the order of execution of these scripts and Named Method user properties??

    The Private Event Submission sample portlet shows how to achieve this. It is part of the PDK download.
    Peter

  • How to stop an execution from a method and thread?

    1,
    public void method(){
    if( something is true)
    //I want to stop this method
    //or if something is false, go on
    blablablablabla
    }Does any one know how to solve the above??
    2,
    Thread t = new Thread(){
    public void run(){
    if( something is true)
    //I want to stop and kill this Thread
    //or if something is false, go on
    blablablablabla
    }Again, how do I solve the above??
    I know this is very simple, but I just hit a wall when I encounter this on making a program for my project.
    please help
    thanks alot

    warnerja, for the method, I have tried "return" but
    it does not work... will it work on the run method of
    thread object??
    Secondly, doesn't "break" keyword only stops the
    execution of a loop/condition, but not the method's
    scope??yes. break breaks the loop. I thought your method doesnt have any other code except the condition.
    use return with thread.

  • How can i calculate execution time for methods?

    I'm making a project that i want to calculate execution time for a
    method in "miliseconds" or "microseconds".You see,I have a sort algorithm and i want to calculate execution time of this algorithm.How can i do?
    Thanks...

    Just remembered.
    The answer you get isn't trustworthy below a hundred millis, so you may need to sort a hundred or a thousand times to get a reasonable elapsed time. You also need to run the test five or ten times and take an average. In Windows you should fire up the Task Manager and be sure that your other CPU usage is as near to zero as you can get.

  • Breaking a Program Execution into Multiple Threads

    Hi,
    We want to run a BAPI with Differenet parameters synchronoulsy in the same program as the BAPI is taking a very lon time for execution.
    We are Planning to break up the execution and the call o the BAPI into multiple threads that can run synchronously. How can this concept implemented in SAP ABAP.
    Thanks in advance.
    Arunava

    I am using parallel processing in my current client. Basis define a dialog processes group that we can use. This way our program will be limited to the number of processing give in the group. For example, our production system has 5 servers and each servers has 15 dialog processes. Basis reserve in the group 5 dialog processes for each group. So when we run our program, we are limited to 25 processes. We use function module SPT_INITIALIZE to find out the number of dialog processes and free processes for our group.
    The logic of the program as follow:
    Do loop
        Call function module with starting new task and destination in group performing end of task subroutine
    Enddo
    Wait until all task completed (check help on wait-you need to keep track of the number of record completed)
    In end of task subroutine, use command receive results from function to get the return parameters.
    Hope this helps.
    Cheers

  • CFTRANSACTION across multiple methods??

    I have a couple of question around CFTRANSACTION
    1) Can I use it around several component calls? eg
    <cftransaction>
    <cfinvoke component="myComponent"
    method="InsertTable1">
    <cfinvokeargument ........ />
    </cfinvoke>
    <cfinvoke component="myComponent"
    method="InsertTable2">
    <cfinvokeargument ........ />
    </cfinvoke>
    </cftransaction>
    2) If this is an inappropriate use of CFTRANSACTION, is there
    a way to programmatically achieve transactioning when database
    inserts/updates/deletes are performed across multiple component
    methods.

    In article <f4t1r9$akd$[email protected]>
    "Swampie"<[email protected]> wrote:
    > I have a couple of question around CFTRANSACTION
    >
    > 1) Can I use it around several component calls? eg
    Yes.
    > 2) If this is an inappropriate use of CFTRANSACTION
    No, this is appropriate.
    Just remember that you can't have a transaction spanning
    operations on
    multiple data sources and, prior to CF8, you cannot have
    nested
    transactions (hence Reactor and Transfer both have a boolean
    flag on
    save() methods to indicate you are wrapping the calls in your
    own
    cftransaction tag.
    Sean
    I'm trying a new usenet client for Mac, Nemo OS X.
    You can download it at
    http://www.malcom-mac.com/nemo

Maybe you are looking for

  • Iphone, Airplay and Apple TV Question

    Question: Will I be able to stream a photo album or HD video shot on an Iphone straight to a TV via Apple TV without syncing through itunes first? I have contacted Apple and one response was that it would already have to be in Itunes, which means I'l

  • Problem with Stack XML file

    Hello, We have an ECC 6 system with EHP 4 SPS 5 and we watn to install a new Technical Usage (IS-OIL, IS-PRA and IS-UT) In order to do that I have to supply an xml file created by the MOPZ. I created a new MOPZ transaction, in the phaze "Update Optio

  • Problem in chinese translation

    Hi All, I am working on chinese translations.  I am using IE 7.0, in which i hv selected language as Chinese (PRC) [zh-CN].  Even after deploying the text is still cummin in english.  Kindly provide some help in resolving this issue. Thanks & Regards

  • IPod Nano - LCD Faulty?

    Hi, I purchased an iPod Nano for my finacee for Xmas. She has just called me to say she thinks it has broken. The iPod is playing music. However, the screen appears to have broken, as all she sees is the backlight come on and dim as it usually would,

  • Transport request not releasing

    Hi All, While releasing transport request it takes more than 24 hours but still not yet released. task has been released. Other requests are releasing and importing going fine. but one request is taking time. Regards Siva