我对一个奇怪的问题感到困惑。基本上情况是这样的。我在我的类中实现了runnable,我在一个新线程中传递了这个类,我在run()
实现runnable的类中覆盖了我的方法,然后我启动了线程。但是,我的start()
方法从不调用我的run()
方法。我搜索了论坛,但似乎找不到另一个类似的问题。
下面是我的示例代码:
public class EmailManager implements Runnable {
PortalManagementSBLocal pmbr= this.lookupPortalManagementSB();
Thread runner;
String emailServerName = "";
String smtpPort = "";
String emailTo = "";
String emailFrom = "";
String mailer = "JavaMailer";
String subject = "";
String message = "";
public EmailManager() {
}//default constructor
public EmailManager(String emailTo, String subject, String message){
this.emailTo=emailTo;
this.subject = subject;
this.message = message;
//need to make this dynamic
this.emailFrom = pmbr.getEmailFrom();
this.emailServerName = pmbr.getEmailServerName();
this.smtpPort = pmbr.getEmailSMTPPort();
//runner = new Thread(this,"Email");
runner = new Thread(this);
runner.start();
System.out.println("***** Email Thread running...");
}
@Override
public void run(){
sendEmail(); //This is never called
}
非常感谢任何指导!万分感谢!