开发者

Can objects instantiated within a static method be overwritten if the method is called on multiple threads?

开发者 https://www.devze.com 2023-01-05 03:48 出处:网络
If you retrieve an instance variable within a static method based on a parameter supplied to the static method, is it possible the instance variable can get stepped on if the static method is called a

If you retrieve an instance variable within a static method based on a parameter supplied to the static method, is it possible the instance variable can get stepped on if the static method is called at exactly the same time by different callers? The method I am calling is defined below and I am wondering if the instance variable invoice can be corrupted... any clarification would be greatly appreciated!

public static void SendInvoiceReceipt(int invoiceId, string recipientEmailAddress)
{
    var invoice = ObjectFactory.GetInvoiceDAL().GetInvoiceByInvoiceId(invoiceId);

    var htmlBody = BuildHtmlInvoiceReceipt(invoice);
    var txtBody = BuildTextInvoiceReceipt(invoice);

    UtilitiesManager.Emails.EmailUtil.Send(SiteConfigUtilities.GetSMTPServer(),
            "referral@realtors.net", recipientEmailAddress, String.Empty,
            "Pay开发者_JAVA技巧ment Receipt", htmlBody, txtBody);
}


invoice is a local variable (not an "instance variable"). It is allocated on the stack, and each thread has its own stack. There is no way for another thread to affect it.

0

精彩评论

暂无评论...
验证码 换一张
取 消