6 Replies Latest reply: Dec 14, 2007 2:59 PM by Matthew Billingham RSS

Is ABAP multi-threading safe?

Davin Wang
Currently Being Moderated

When implementing the Singleton design pattern in Java, we must use keyword <b>synchronized</b> with <b>getInstance()</b> method to ensure multi-threading safety, so that we can get the one and only instance.


    What shall I do in ABAP? or just leave it alone?  Would you help me find a example?


    thanks and regards,


  • Re: Is ABAP multi-threading safe?
    Davin Wang
    Currently Being Moderated

    The question is still pending.



  • Re: Is ABAP multi-threading safe?
    chandra sekhar kantimahanti
    Currently Being Moderated



    Multi Threading concept is there for ABAP. The concept behind is executing the jobs by priority wise.


    For example :


    If the processer have 10 jobs to execute it will assign thread to each job and based on the priority processer will executes the jobs.



    This link may help:




    This type of programming can be done using function modules and using the syntax, STARTING NEW TASK


    Reward points if found helpful…..



    Chandra Sekhar.

    • Re: Is ABAP multi-threading safe?
      Davin Wang
      Currently Being Moderated


          Thanks, but I cann't catch with you. l think I can split this thread into 2 questions.


          1.When I using Singleton pattern, how many instance will I get in the ideal condition?

            I think the answer "only one instance" is limited. For example, maybe one instance for each session? One instance for each application server? Or, one instance across clustered application server?


          2.If the answer is "One instance for each application server", then how can I eliminate the situation when 2 session(in 2 threads/processes) starts simultaneously? (suppose I'm using Singleton in lazy mode)

      public class Singleton {
          static private Singleton instance=null;
          private Singleton(){}
          synchronized static public Singleton getInstance() {
              if (instance==null) 
                  instance=new Singleton();
              return instance;


          my internet connection is broken now, so i'll check the wiki later.

      • Re: Is ABAP multi-threading safe?
        Rudolf Wiesmayr
        Currently Being Moderated

        I 'm not familiar with ABAP Objects, but...


        I presume you have an implementation that succeeds in "Ensuring an unique instance" (GoF p. 128).


        How about just using the enqueue server?

        If this hidden method does an ENQUEUE before creating the singleton variable, no other process can do the same thing at this moment.


        HTH, Rudi

      • Re: Is ABAP multi-threading safe?
        Clemens Li
        Currently Being Moderated

        Hi Davin,


        I do not understand fully what you are going to do in ABAP terms so I hope my comment will be of any value.


        Multithreading may be achieved in ABAB by calling a function with the addition STARTING NEW TASK IN GROUP.... See my sample program for <a href="https://wiki.sdn.sap.com/wiki/display/Snippets/Easilyimplementparallelprocessinginonlineandbatchprocessing">Easily implement parallel processing in online and batch processing</a>


        The second question may be solved by help of SAP lock concept. This is used primarily to secure a consistent database by not allowing two processes to change data at the same time. Chose a lock object of your choice and set at start of first instance. At end, remove the lock. Before creating the second instance, try so set the same lock. If you get a foreign lock error, you know the process is running.


        See documentation on lock objects on how to lock/unlock.






        Hope your internet connection is broken no longer so you can read this.

      • Re: Is ABAP multi-threading safe?
        Matthew Billingham
        Currently Being Moderated



        The concepts you describe don't readily fit into the way ABAP works.  The answers will very much depends on precisely what you are doing and what you are trying to achieve.  For instance, is your class shared, persistent?  Do you understand how SAP and ABAP memory works?


        I propose you post this question in the ABAP Objects forum.  I think also you might find OK - I got a really interesting question down in ABAP General and NW AppSer discussion of interest.