cancel
Showing results for 
Search instead for 
Did you mean: 

Is SAPbobsCOM.Company thread-safe?

Former Member
0 Kudos

Hey guys,

I have a question about the SAPbobsCOM.Company multi-threading capabilities. Here it goes…

Does SAPbobsCOM.Company handle simultaneous multiple-thread accesses while executing database operations? Or other operations for that
matter? Is it thread-safe?

Or do I need to create-bind a company to each created thread? Making this way a one-to-one relationship between them?

I’m asking because I don’t like having multiple Company objects created and connected to the same Company, that object is expensive to create and connect.

Any thoughts?

Thanks in advance!

Lorenzo

Accepted Solutions (1)

Accepted Solutions (1)

edy_simon
Active Contributor
0 Kudos

Hi Lorenzo,

I know this is an old discussion, but I will just share my experience.

I had tried to spawn 2 threads using the same company to create Delivery Drafts object.

During the process, the SQL Server process would almost always get a deadlock process, which means the whole SAP would hang.

I would then need to go into the SQL Server to kill the blocking process manually.

So, in this sense I would say that SAPBobsCom.Company is not thread safe.

Regards
Edy

Former Member
0 Kudos

Hi Edy,

Thanks for your answer. I did try to look for any pitfalls while using the Company object across multiple threads, and I did encounter issues. This is an un-documented fact that should be visible or mentioned on the SDK documentation.

What I ended up doing, to overcome this limitation, is to implement the Object Pool design pattern. So I created and connected 4-5 Company objects that can be used from the pool.

Everytime a thread needs a Company, it waits until one is available, it takes it from the pool. As soon as the thread finishes it puts the company back in the pool again for other threads to use.

I think that's the most efficient way when having multiple threads requiring to perform operations against SAP in an asynchronous way.

Regards

Lorenzo

edy_simon
Active Contributor
0 Kudos

Hi Lorenzo,

Thanks for sharing your solution.

I tried also spawning a new thread with a completely new company, but also having problem with the SQL deadlock.

I ended up creating another executable to run the worker processing. The main addon will then send a shell command with line arguments.

Finishing the Job, the external executable will send an alert in SBO to the user.

I need this because the worker process will run a very long process.

I know it is expensive to have 2/more companies at once, but with current memory size of PCs, this is still workable. And my user can still use the whole SBO and/or the main Addon while my worker is running.

Regards
Edy

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Edy,

Thanks again for the feedback,I have a sample project with the solution if anybody interested. I think, if each thread handles potentials deadlocks as explained in this discussion http://scn.sap.com/thread/1768988 everything should be fine. I haven't been able to replicate any outstanding issue, although with threading, if I did a mistake, sooner or later it will come to float.

If interested, email me or reply to this post with your email so I can send you the solution.

Many thanks,

Lorenzo

Eneveux
Product and Topic Expert
Product and Topic Expert
0 Kudos

Lorenzo,

Currently the API's provided by the SDK, such as the DI API, are not mult-threaded.

Eddy

Former Member
0 Kudos

Hi Lorenzo,

    Doing single SAPbobsCOM.Company for all entries is good.  check Company is connected before make transactions.

With regards,

Venki .A