Killing a NotesThread

I have written a little external Java tool that does some auditing on the server logs. The issue is that sometimes, the views I am reading aren’t up-to-date and the tool blocks on the “View.createViewNav()” method. So basically it stalls on that code. Note I am not interested in fixing or updating the index on the view so “run Updall” isn’t the solution.What I would like to do is to either kill the thread reading the view or perhaps set a timeout on the method.

The initiation of the thread looks like this…

[

private void processServer(final String server, final String fileName) {

if (worker == null || !worker.isAlive()) {

    worker = new NotesThread(new Runnable() {

        public void run() {

            try {

               cancelMenuItem.setEnabled(true);

                 process(server, fileName);

                 cancelMenuItem.setEnabled(false);

            } catch (InterruptedException e) {

                e.printStackTrace();

            } catch (Exception e) {

                e.printStackTrace();

            }

         }

      });

  worker.start();

} else {

    JOptionPane.showMessageDialog(this, "Process already running");

}

}

]

The createViewNav method is in the processServer(string,string) call. The (Notes)Session used in the processServer method is a class member originally initiated from a NotesThread.sinitThread context within the main thread. Only one worker can be running at a time.

I’ve tried issuing an interrupt to worker but it seems to have no effect. I can’t see a way to force the timeout without possibly creating a third thread just to create the ViewNav. But that involves it’s own problems.

I’ve also thread a termThread on worker but that threw some really nasty errors.

Any help is appreciated

Thanks

Zach Mabe

Subject: Killing a NotesThread

There’s no clean way to forcibly kill a running java Thread (and hence a NotesThread) other than returning from the run() method or by setting it as daemon Thread and performing a System.exit().

You used to be able to just stop() a thread, but that introduced a lot of nasty ways to get deadlock ed – so it was justly deprecated.

From within the regular Java API there is no way to stop your worker thread or instruct it to not update the view index.

If you’re comfortable with the Lotus C API and know your JNI you may be able to do the lookups using NIFOpenCollection/NIFReadEntries, which has a specific flag to not update the view index. But that approach is not for the faint of heart.

cheers,

Bram