19

Are client stubs generated from WSDL by Axis2 thread-safe?

Of course, "thread-safe" isn't necessary a rigorously defined term, so I'm at least interested in the following:

Are different instances of the same stub class accessible concurrently by different threads, with the same effective behavior as single-threaded execution?

Is a single instance of the same stub class accessible concurrently by different threads, with the same effective behavior as the same calls interleaved in some arbitrary way in single-threaded execution?

You may also wish to use the terminology described here (and originating here) to discuss this more precisely.

BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
  • I was under the impression that Apache Axis2 was being phased out in favor of Apache CXF: http://cxf.apache.org/ – Powerlord Jan 04 '10 at 21:34
  • That may be, but my question still stands as I don't have the liberty of changing our underlying framework at the moment (someday, maybe:)... – BeeOnRope Jan 04 '10 at 23:20

3 Answers3

22

I'm not sure about axis2, but at least axis1 generates non-threadsafe client stubs. I got the impression pretty much every other SOAP client was non-threadsafe as well. If I remember correctly the issue was with the XML parsing library being used in a non-threadsafe way by the client stub.

Using apache commons-pooling to pool the instances and using each one from one thread at a time worked well though.

Update: For Axis2, see https://issues.apache.org/jira/browse/AXIS2-4357 (claims Axis2 is not threadsafe, by design)

Stefan L
  • 1,529
  • 13
  • 20
  • 1
    To be clear, you mean that you cannot use the *same* instance from multiple threads, but using multiple instances (of the same stub class) from multiple threads is OK as long as there is no concurrent access to any given instance? – BeeOnRope Jan 04 '10 at 18:16
  • Yes. And apparently stub instances don't have to be bound to a certain thread either. – Stefan L Jan 08 '10 at 07:15
  • But the author below states that axis stubs are stateless, and therefore can be safely accessed from multiple threads concurrently: http://stackoverflow.com/questions/1950080/are-axis2-generated-stubs-thread-safe/1968188#1968188 – Danubian Sailor Aug 24 '11 at 07:31
  • Funny, this question has an answer claiming Axis2 is not threadsafe, with a JIRA issue to back it up: http://stackoverflow.com/questions/5977997/axis2-generated-stubs-are-thread-safe links to https://issues.apache.org/jira/browse/AXIS2-4357 – Stefan L Aug 28 '11 at 21:02
  • I've voted this answer up, primarily because it's not the fault of Stefan L that I now have a good amount of refactoring to do... – Mike Yockey May 15 '12 at 13:04
3

I guess I'll try to answer my own question by providing some update on futher research I did. It appears that by default older versions of Axis2 stubs may have been only "thread-compatible" (cannot make calls on the same stub instance concurrently from multiple threads - but calls to different instances is OK).

See for example:

http://markmail.org/message/3lu7x7pfo47vgnck http://markmail.org/message/sljyf6lpecxqllgx

You may experience some socket leaks, and run out of sockets if you don't call cleanup/cleanupTransport, as per this thread and many related ones:

http://issues.apache.org/jira/browse/AXIS2-3670

In some cases, at least the underlying HttpClient now seems to be thread-safe, but depending on how you generated your client, the entire stub might not be:

http://amilachinthaka.blogspot.com/2009/05/improving-axis2-client-http-transport.html

BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
2

These stubs are stateless allowing reuse of the stub instances. Can you please elaborate on the problem you are facing with Axis2. People usually recommend Xfire over Axis.

Ravi Gupta
  • 4,468
  • 12
  • 54
  • 85
  • I thought XFire was defunct and folded into another project – Jherico Dec 28 '09 at 06:44
  • You can call CXF as XFire2.0 , I am bit biased towards it :) – Ravi Gupta Dec 28 '09 at 06:56
  • 1
    Thanks for the answer - can you comment on what level of thread safety is offered? You can call any method on the same object from any number of threads concurrently and get the expected behavior? I'm not experiencing any particular problem with Axis2 - just that we've created stubs using the framework and need to quantify the thread-safety level for such components. This is (relatively) easy for the stuff you write yourself, but more difficult for the auto-generated stuff. – BeeOnRope Dec 28 '09 at 23:00
  • What is the data binding you are using..? – Ravi Gupta Dec 29 '09 at 06:07
  • We are using XMLBeans data binding. – BeeOnRope Jan 04 '10 at 23:19
  • Have you used axis stubs in such ways, t.m. simultanous calls from multiple threads? The guy above stated that axis stubs are not thread safe. – Danubian Sailor Aug 24 '11 at 07:33