From: thomas at tada.se (Thomas Hallgren) Date: Tue, 21 Mar 2006 19:19:24 +0100 Subject: [Pljava-dev] pljava reninitializing jdbc connection pool for every invocation In-Reply-To: <6992E470F12A444BB787B5C937B9D4DF03C48ACF@ca-mail1.cis.local> References: <6992E470F12A444BB787B5C937B9D4DF03C48ACF@ca-mail1.cis.local> Message-ID: <442043AC.1070702@tada.se> 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