0

您好我正在尝试使用以下代码在 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 中运行线程并尝试访问其他数据库时都会遇到问题,我收到此错误:

    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)

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

4

0 回答 0