Forum OpenACS Q&A: Response to Storing java Objects in PostgreSQL

Collapse
Posted by Dan Wickstrom on
You might try experimenting with the ns_thread command.  You could start a detached thread that runs java code, via ns_javablend, that acts as an object store.  That way you could pass java objects off to the detached thread for storage in a HashTable which is indexed by a generated id.  The id could then be passed between pages using form variables, and the succeding pages in the page-flow sequence would be able to retreive the object from the object-store.  At least in theory, I think this is doable.  One thing to remember is that Tcl_Obj's (tcl variables are stored as pseudo multi-ported objects) cannot be passed between threads, so you can't create a tclobject in one thread by doing something like:

set x [java::new foo ...]

and then pass "x" to the detached thread.  You could however pass the object from one thread to another from the java side, and retain a label to the object so that you can fetch it later.  The label could then be passed around between the aolserver connection threads if necessary.

I've never tested ns_javablend with detached threads, so I'm not sure that it would work.  In aolserver everything centers around connection threads, and there might be some quirks with making everything work with a detached thread.  ns_javablend does work with scheduled procs, and I don't think there is much of a difference between the thread that does proc scheduling and a detached thread, so hopefully using ns_javablend from a detached thread will also work.