首页 > 学院 > 开发设计 > 正文

Java对Domino Objects的访问 (2)

2019-11-18 14:12:45
字体:
来源:转载
供稿:网友

通过继续来执行线程


    要通过继续来执行线程,需要扩展 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();
            }
        }   
    }
 



发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表