如果在多个线程上调用静态方法中实例化的对象,是否可以覆盖该方法?
如果您根据提供给静态方法的参数检索静态方法中的实例变量,如果不同的调用者同时调用该静态方法,该实例变量是否有可能被踩踏? 我调用的方法定义如下,我想知道实例变量发票是否会被损坏......任何澄清将不胜感激!
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(),
"[email protected]", recipientEmailAddress, String.Empty,
"Payment Receipt", htmlBody, txtBody);
}
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(),
"[email protected]", recipientEmailAddress, String.Empty,
"Payment Receipt", htmlBody, txtBody);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
invoice
是一个局部变量(不是“实例变量”)。它是在栈上分配的,每个线程都有自己的栈。另一个线程无法影响它。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.