[Pljava-dev] pljava reninitializing jdbc connection pool for every invocation

Thomas Hallgren thomas at tada.se
Tue Mar 21 18:19:24 UTC 2006


Sriram Dandapani wrote:


> How thread-safe is this connection. If I were to use just 1 connection,
> does pljava guarantee safe concurrent access
>
>   

There will never be concurrent access to a connection. PostgreSQL 
guarantees that, not PL/Java.


> Which begs the question:
>
> Does every call to pljava function create a separate jvm...

No, of course not. It's one JVM *per connection*. You can have millions 
of calls per connection. My point is, they are never parallel so you 
have absolutely no use of a pool from within a PostgreSQL function (be 
it Java or some other language).


> Lets say
> there are cron jobs that are kicked off periodically and lots of
> postgres functions are invoked. Each function calls the pljava function
> several times. What is the overhead in terms of jvm startup/connection
> creation?
>
>   

Each new connection spawns a new JVM. During the life of the connection, 
each call is extremely efficient (due to in-process calls).


> Does the java function that obtains the connection need to worry about
> all this or is a simple jdbc connection creation mechanism sufficient. I
> am not familiar with pljava internals.
>
>   
I'm sorry. I don't understand this question. Worry about what exactly?


> Also, do we need to use the postgresql.jar file or will just pljava be
> sufficient
>
>   

PL/Java has its own JDBC driver. This driver is special in that it will 
connect you to the current transaction (the transaction in which the 
PL/Java function call was made). Each call you make using this driver 
will execute within the scope of the current transaction. If your 
objective is to have autonomous transactions that execute independently 
of the one that is current, then you must connect to another session, 
i.e. another backend process. That in turn, will require you to use the 
client jdbc driver (i.e. the postgresql.jar).

Regards,
Thomas Hallgren





More information about the Pljava-dev mailing list