Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Is ABAP multi-threading safe?

Former Member
0 Kudos

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,

Davin,WANG

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

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:

http://en.wikipedia.org/wiki/Thread_%28computer_science%29

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

Reward points if found helpful…..

Cheers,

Chandra Sekhar.

6 REPLIES 6

Former Member
0 Kudos

The question is still pending.

thanks

Former Member
0 Kudos

Hi,

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:

http://en.wikipedia.org/wiki/Thread_%28computer_science%29

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

Reward points if found helpful…..

Cheers,

Chandra Sekhar.

0 Kudos

hi,

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.

0 Kudos

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

0 Kudos

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.

Regards,

Clemens

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

matt
Active Contributor
0 Kudos

Davin,

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 discussion of interest.

Regards

matt