문제

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 ?

도움이 되었습니까?

해결책

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.

다른 팁

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.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top