XPage中的多个线程Notescontext错误

时间:2013-11-22 08:08:44

标签: java xpages xpinc

您好我正在尝试在XPage上创建多个线程 使用以下代码

public class ThreadTest implements Serializable {

private transient Vector<Integer> exvec;

private transient Map<String, Thread> searchThreads = new HashMap<String, Thread>();
private static final long serialVersionUID = -2503920777570603336L;
 // ------------------------------------------------------------------------

private class SearchThread extends Thread {

private ThreadSessionExecutor<IStatus> executor;
private final ThreadTest owner;

private boolean ready = false;

public boolean isReady() {
    return this.ready;
}

public SearchThread(final ThreadTest owner, final String dbKey) {
    this.setName("SearchThread-dbKey-" + dbKey);
    this.owner = owner;

    this.executor = new ThreadSessionExecutor<IStatus>(true) {
    protected IStatus run(Session session) throws NotesException {

        Database db =session.getDatabase("TestServer", "TestDB",false);
        if(db.isOpen())
        {
            exvec.add(db.getAllDocuments().getCount());
        }



        return Status.OK_STATUS;
    }
    };
}

public void run()  {
    try {
    this.executor.run();
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    // release the monitor...
    synchronized (this.owner) {
        if (!isReady()) {
        ready = true;

        this.owner.notifyAll();
        }
    }
    }
}
}

public ThreadTest() {

    searchThreads = new HashMap<String, Thread>();
    exvec = new Vector<Integer>();
}



public void isThreaddingAvailable()
{


        searchThreads.put("Test", new SearchThread(this, "Test"));



        // step 2 - spawn each searchthread to run asynchronously...
        for (Map.Entry<String, Thread> searchThreadEntry : searchThreads.entrySet()) {
            SearchThread searchThread = (SearchThread) searchThreadEntry.getValue();

        searchThread.start();
        }

        // step 3 - wait until all searchthreads have completed...

        for (Map.Entry<String, Thread> searchThreadEntry : searchThreads.entrySet()) {
        SearchThread searchThread = (SearchThread) searchThreadEntry.getValue();
        synchronized (this) {
            while (!searchThread.isReady()) {
            try {

                this.wait();
            } catch (InterruptedException e) {
            }
            }
        }
        }
        System.out.println(exvec);

}
}

但每次在XPinc中运行Thread并尝试访问其他数据库时,我都遇到了问题 我收到了这个错误:

    java.lang.SecurityException: NotesContext cannot be null for ECL permission check
   (java.lang.RuntimePermission modifyThreadGroup)
    at com.ibm.domino.xsp.module.nsf.platform.NotesPlatform.checkPermission(Unknown Source)
    at COM.ibm.JEmpower.applet.XPagesSecurityManager.checkPermission(Unknown Source)
    at COM.ibm.JEmpower.applet.XPagesSecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkAccess(Unknown Source)
    at COM.ibm.JEmpower.applet.XPagesSecurityManager.checkAccess(Unknown Source)
    at java.lang.ThreadGroup.checkAccess(Unknown Source)
    at java.lang.ThreadGroup.getParent(Unknown Source)
    at lotus.domino.NotesThread.getAgentThreadGroup(Unknown Source)
    at lotus.domino.NotesThread.bumpStaticActiveNotesThreadCount(Unknown Source)
    at lotus.domino.NotesThread.sinitThread(Unknown Source)
    at com.ibm.domino.xsp.module.nsf.NotesContext.initThread(Unknown Source)
    at com.ibm.domino.xsp.module.nsf.ThreadSessionExecutor.run(Unknown Source)
    at de.itwu.bean.ThreadTest$SearchThread.run(Unknown Source)

有没有人有想法解决这个问题?

0 个答案:

没有答案