Subject: NotesSession thread Terminates independantly of the JVM thread.
The link to another discussion thread, (pardon the pun), below highlights almost the exact same problem. From my own experiementation I have come up with this theory. Think of 2 memory stacks… one for the JVM and one for the domino server.
It seems to be that even though I use static classes or variables, the exception that gets raised, “NotesException: Object has been removed or recycled”, is a notes exception which means that the JVM has passed it through to the domino server which has thrown a wobbly at my seemingly sensible request. The JVM is oblivious to the domino environment. Why ?
Probably because the database class like many other notes-java api’s are just wrappers, and so the JVM doesn’t really know what’s happening on the domino server. It only has an interpretation by these intermediary wrapper classes.
Once the notes session is finished with whatever it’s doing it just terminates it’s thread and everything belonging to it even though you have politely asked the servlet/JVM to keep static instances. A simple test for null, does not actually goto the domino server it only tests the wrapper. This weak linkage between these objects is probably for reasons of efficiency.
But the actual object on the domino server is looong gone.
So then your code running in the JVM thinks, “ok, it’s not null, now lets get that object”, by making a request to use a method/property. Now the JVM says to the domino server, “run adminDB.FOO()”. The domino server, for the trailer-park whore that it is sometimes, gets this request and says “Method FOO of what ? I gave that memory away ages ago, get stuffed… Object has been removed/recycled”. Thus a domino object that does not look null is in fact null, the wrapper is not null, but the actual object is no longer assigned.
So don’t expect requests for thread persistence to also remain persistent on the domino server. To solve this then, I re-instantiate the object every time the servlet is called. This ensures that the JVM object is synchronised with the domino session environment as well. I still use a static variable but it “freshened” in the servlet every time I run doGet/doPost.
If there is a clean way to handle threads and persistence in domino servlets I am all ears
http://www-10.lotus.com/ldd/nd6forum.nsf/0/66951de35ed7ce4885256ebe005e77a0?OpenDocument
I did find this from lekkimworld which is a first pass solution, but not quite suitable for my implementation.
http://lekkimworld.com/lekkimworld/replyToComment.action?entry=1137847652985&comment=1140529034976