[Pljava-dev] java.sql.SQLException: An attempt was made to call a PostgreSQL backend function while main thread was not in the JVM - RESOLVED!

Thomas Hallgren thhal at mailblocks.com
Sun Sep 19 17:14:27 UTC 2004


Petr Michálek wrote:

> It was my fault! I forgot to close prepared statement!
>
> WARNING:  Freeing plan using finalizer. Someone forgot to close a 
> PreparedStatement
> LOG:  Exception
> LOG:  in thread "main"
> java.sql.SQLException: An attempt was made to call a PostgreSQL 
> backend function while main thread was not in the JVM
>     at org.postgresql.pljava.internal.TriggerData._isFiredAfter(Native 
> Method)
>     at 
> org.postgresql.pljava.internal.TriggerData.isFiredAfter(TriggerData.java:219) 
>
>     at 
> com.aca.app.acc.core.postgresql.Triggers.document1(Triggers.java:569)
> ERROR:  java.sql.SQLException: An attempt was made to call a 
> PostgreSQL backend function while main thread was not in the JVM

Ok, that explains it. What happens is that eventually a finalizer is 
called from a thread other then the one spawned by the original function 
call. That thread in turn makes an attempt to call back into the backend 
C functions in order to free up an SPI execution plan. The that call 
arrives at a time when the backend is not executing a Java function so 
PL/Java has no choice but to let it bounce back into Java with an 
exception. The PostgreSQL backend is inherently single threaded. It 
cannot serve multiple requests stemming from different places at the 
same time.

I might improve this some time in the future by introducing some kind of 
"death row" that is processed when it's safe.

Regards,

Thomas Hallgren





More information about the Pljava-dev mailing list