0

I have a non-static class which has a static method

public class ITelcoServicesFactory
{
  public static ITelco GetITransactionHandler(int pTelcoId, int pTransactionMode)
  {
        ITelco lITelcoServices = null;
        if (pTelcoId < 0)
        {               
            lITelcoServices = new DUMMY_Impl(pTransactionMode);
            mLogger.Debug("ITransactionHandler Dummy Implementation");
        }
        return lITelcoServices;
  }

}

this method return instance on the basis of parameters. i am confuse "If multiple transaction comes at the same time will there be any issue with this method" ?

i mean multiple transaction at same time will override this method ? or every transaction will get it own object on the basis of parameters ?

PS : If it does not any harm than why ?

1
  • yes i missed return statement .. however please tell my why this would not have any issue ? Commented Mar 18, 2014 at 8:18

3 Answers 3

2

The only danger I see are these lines:

lITelcoServices = new DUMMY_Impl(pTransactionMode);
mLogger.Debug("ITransactionHandler Dummy Implementation");

The code of the DUMMY_Impl constructor should be examined.

And obviously you are sharing mLogger.

Have a close look (and/or post it here) at its Debug method to make sure you are not running into concurrency issues there.

Sign up to request clarification or add additional context in comments.

Comments

2

I don't know how all the previous people are so sure you're not using any shared resources. You are obviously sharing the logger, and there's no telling what your DUMMY_Impl constructor does.

Most loggers are thread-safe, so it boils down to your dummy implementation constructor. If it's thread-safe, your function is thread-safe.

1 Comment

Maybe they missed the logger because they can't see it declared anywhere ;)
1

As you are not using any static variables, you will not run into multi threading issues. All the local variables created will be available only for that thread and hence you are good.

This is not the case when you are using any static variables as they share the only instance with multiple threads

2 Comments

can you please explain why it would not be any harm ?
All the local variables created will be available only for that thread and hence each thread would get its own copy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.