I have a very complex stand-alone Java program, which I call a “connector”, which uses multi-threading and the Notes Object Interface for Java.It is not an agent. It handles connections from clients, connects to a Domino server (creates a session), and returns data to those clients.
I am trying to understand exactly how my program should behave with multi-threading.
A. Not long ago, it was crashing.
B. Recently, it was throwing an exception.
C. Now, it appears to be behaving correctly; but, I’m not sure.
Every connection creates a unique session.
Theoretically, every connection executes on a separate thread.
Unfortunately, since the threads are managed from a fixed sized thread pool (which my code has no control over),
it is possible that multiple connections (sessions) will execute on the same thread.
A. Initially, here was how my “connector” program behaved:
- When the connection is created, my “connector” program:
a) calls NotesThread.sinitThread (if the Domino server is local)
b) creates a Domino session
- When the connection is closed, my “connector” program:
a) calls Session.recycle
b) calls NotesThread.stermThread (if the Domino server was local)
Unfortunately, I recently found out that there may not be a separate thread for every connection.
So, when I used to call NotesThread.stermThread when I was done with connection/session 1,
and then try to access something with connection/session 2 (on the same thread), the program would crash.
B. Then, I started tracking which threads had been initialized, and which threads and been terminated,
Before each Domino API call, I would make sure the thread had been initialized (and reinitialized if it had been terminated).
Even after that, sometimes my program would throw an exception since it was trying to use a view that another thread had recycled.
C. Someone suggested that the solution was to simply never call NotesThread.stermThread.
That seems to work for now - but I don’t believe it is the right long term solution.
I don’t know what NotesThread.stermThread does, and what happens if I don’t call it.
I don’t know if I now have a memory leak or other resource loss.
So, my bottom line questions are:
-
What does NotesThread.stermThread do, and more importantly, what happens or might happen if I don’t call it?
Please note, I am calling Session.recyle.
-
What happens if I recyle a session or session object on a different thread than the one which created it?
Thanks,
Chuck