Hi,
I have a problem with PL/Java that, if it's going to have a good
solution, requires your help.
PL/Java runs a JVM. Since a JVM is multi threaded, PL/Java goes to
fairly extreme measures to ensure that only one thread at a time can
access the backend. So far, this have worked well but there is one small
problem. Here's a use-case:
Someone loads a library that contains a method that spawns a new thread.
That thread is the first to access some class. The class loader will now
make an attempt to load it. PL/Java uses SPI to load classes so a call
is made to SPI. This call is not made from the main thread that
originally called the PL/Java function. That thread is suspended at this
point.
Now, the check_stack_depth() in postgres.c is called. The new thread has
a stack of it's own of course, so it fails.
I know that multi threading is very controversial and I'm in no way
asking that the backend should support it. What I would like is a
workaround for my problem. The easiest way would be if I could change
the stack_base_ptr temporarily when this happens, a try/catch that kicks
in when I detect a call from a thread other then main. The only other
solution is to set the max_stack_depth to a ridiculously high value and
effectively turn stack checking off. I don't want to do that.
Any opinions on this?
Kind regards,
Thomas Hallgren