Java对Domino Objects的访问 (2)

王朝java/jsp·作者佚名  2008-05-31
宽屏版  字体: |||超大  

通过继续来执行线程

要通过继续来执行线程,需要扩展 NotesThread,而不是 Thread,并且需要包含 runNotes 方法,而不是 run 方法。NotesThread 线程可以和任何其他线程一样通过 start 方法来启动。这种方式比静态方法(稍后讨论)轻易使用,且不易出错。

import lotus.domino.*;

public class myClass extends NotesThread

{

public static void main(String argv[])

{

myClass t = new myClass();

t.start();

}

public void runNotes() // entry point for Notes thread

{

try

{

Session s = NotesFactory.createSession();

// Operational code goes here

}

catch (Exception e)

{

e.printStackTrace();

}

}

}

通过 Runnable 接口来执行线程

要通过 Runnable 接口来执行线程,需要实现 Runnable 并包含 run 方法,这与使用线程的任何类相同。当您因为正在扩展其他类而不能扩展 NotesThread 时,可以使用这种方式。

import lotus.domino.*;

public class myClass implements Runnable

{

public static void main(String argv[])

{

myClass t = new myClass();

NotesThread nt = new NotesThread((Runnable)t);

nt.start();

}

public void run() // entry point for thread

{

try

{

Session s = NotesFactory.createSession();

// Operational code goes here

}

catch (Exception e)

{

e.printStackTrace();

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有