0

Consider this 'pattern' I encounter in a application I inherited:

public class BusinessUtil{
    public static void doBusiness(IService myService, String arg1, int arg2){
        //something something
        myService.doStuff(arg1, arg2);
    }
}

The myService bean is a springBean (=singleton). It is actually a cxf-client (=generated webservice-client)

This is in a webapplication, so the static doBusiness() method is called from different concurrent threads. Is this method thread-safe?

Before you ask: I know this is a weird 'pattern'. I know the doBusiness() method is quite redundant since we can call myService.doStuff() directly instead of passing it into a static method, where it is called. As I said, I inherited an application where this 'pattern' is all over the place. I do not know why. The application has (sometimes) some strange behaviour and I'm trying to locate the source of the problem.

thomash
  • 95
  • 1
  • 5

2 Answers2

2

There is nothing in doBusiness() that make it thread-unsafe. Whether it is thread safe or not depends on thread-safetiness of myService.doStuff(arg1, arg2);

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
  • thanks! Are there other considerations to make with this approach? I mean, when would you use this approach: `BusinessUtil.doBusiness(service, arg1, arg2)` instead of the more intuitive `service.doStuff(arg1,arg2)`? I ask because the 'pattern' I described in my question doesn't make much sense to me. – thomash Mar 07 '13 at 08:22
  • well, to be honest such "pattern" doesn't seems making any sense to me either (if it is actually doing what you wrote). However after working in development field for many years, I have seen a lot of people actually doing lots of "abstractions" or "pattern" that make no sense :P – Adrian Shum Mar 08 '13 at 03:28
0

Whether it's thread-safe or not depends on myService.doStuff(arg1, arg2); Since it is cxf-client this article Are CXF client proxies thread safe? may be useful

Community
  • 1
  • 1
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275