Re: How to shutdown OJB when stopping web context.

2005-03-24 Thread Danilo Tommasina
Hi,
we use following two calls to shut it down
  // Release all persistence broker instances
  PersistenceBrokerFactory.releaseAllInstances();
  // Release all pooled db connections
  
ConnectionFactoryFactory.getInstance().createConnectionFactory().releaseAllResources();
however it could be that the DBCP connection factory implementation in OJB 
1.0.1 does not closes the connections when calling the methods above.
I think Martin fixed this in OJB 1.0.2
danilo
Hi all,
I am looked through the source code, through the archives and searched the
OJB site http://db.apache.org/ojb/, but I can still not figure out how OJB
is shutdown.
We have a very serious problem with our connection pool at the moment. Part
of that is to do with the connection pool that OJB uses and how it is shut
down. At the moment when I stop our web application context through the
Tomcat Manager it shuts down cleanly. The application's connection pool
shutdown method is called and all connections are closed. The OJB connection
pool is leaving connections open. Once Tomcat is stopped all connections are
closed as indicated by the Database monitor.
I would like for all connections to be closed when our web context is
stopped. How can this be done for OJB?
Any help greatly appreciated.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: How to shutdown OJB when stopping web context.

2005-03-24 Thread Martin Kalén
Greetings all,
 first off - all the different hints of how not to leave open 
connections at webapp shutdown (ie using DBCP in Tomcat and supply JNDI 
DataSource to OJB, or explicitly calling release methods in OJB at 
shutdown) are equally good ways of doing.

Danilo Tommasina wrote:
however it could be that the DBCP connection factory implementation in 
OJB 1.0.1 does not closes the connections when calling the methods above.
I think Martin fixed this in OJB 1.0.2
That's correct. So if you are using DBCP as connection factory in 
OJB.properties, releaseAllResources will not close the connections in 
v1.0.1 or earlier.

Finally, for the sake of clarity: using a DBCP Connection pool in Tomcat 
and supplying a JNDI DataSource to OJB is not affected by this since the 
Connection management is then entirely left to Tomcat.

Regards,
 Martin
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: How to shutdown OJB when stopping web context.

2005-03-24 Thread Nathan Smith
Thanks for all your very useful replys.

We do all closing of resources in the destroy() method of our setup servlet.

We use the ConnectionFactoryPooledImpl so releasing of the resources used
should work fine.

I would have like to have used the ConnectionFactoryDBCPImpl as that is what
is used for the rest of the application (We have a connection pool used by
OJB and a connection pool for native SQL queries).

I cannot quite remember what the problem was, but it had something to with
Iterators not returning all objects or Collections being returned containing
no objects, but that’s better left for another time at the moment.

Now all I have to do is work out where the connection leak is in the
application connection pool.

The connection pool implementation uses DBCP. The code is similar to other
implementations I have looked at and is based on the OJB version.

It looks as though the leak may be in the code, but I have already gone over
it to match up the use of getConnection() methods with recycleConnection()
methods. All recycles are in finally methods.

I thought that the leak may be occuring in the DBCP code when it is making
sure that the maxIdle value is met and the connection is somehow just not
referenced anymore.

When the web context is shutdown there are connections left open, which can
be seen in the Database monitor. Once Tomcat is shutdown all the leftover
connections are closed. The finalize() methods are being called by the GC,
which in turn closes the connections, I think.

Any more suggestions?



 -Original Message-
 From: Martin Kalén [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, 24 March 2005 8:56 p.m.
 To: OJB Users List
 Subject: Re: How to shutdown OJB when stopping web context.
 
 
 Greetings all,
 
   first off - all the different hints of how not to leave open 
 connections at webapp shutdown (ie using DBCP in Tomcat and 
 supply JNDI 
 DataSource to OJB, or explicitly calling release methods in OJB at 
 shutdown) are equally good ways of doing.
 
 Danilo Tommasina wrote:
  however it could be that the DBCP connection factory 
 implementation in
  OJB 1.0.1 does not closes the connections when calling the 
 methods above.
  I think Martin fixed this in OJB 1.0.2
 
 That's correct. So if you are using DBCP as connection factory in 
 OJB.properties, releaseAllResources will not close the connections in 
 v1.0.1 or earlier.
 
 Finally, for the sake of clarity: using a DBCP Connection 
 pool in Tomcat 
 and supplying a JNDI DataSource to OJB is not affected by 
 this since the 
 Connection management is then entirely left to Tomcat.
 
 Regards,
   Martin
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to shutdown OJB when stopping web context.

2005-03-24 Thread Martin Kaln
Nathan Smith wrote:
I cannot quite remember what the problem was, but it had something to with
Iterators not returning all objects or Collections being returned containing
no objects, but thats better left for another time at the moment.
Aha, this smells like objects of class OJBIterator returned when using 
PB-API and report-queries or iterating Collections that are using proxy 
objects in OJB.

In OJB 1.0.x the API will specify Iterator as return type so you have to 
do a somewhat ugly cast to (OJBIterator) and call #releaseDbResources() 
if you want to free resources from unexhausted [*] iterators before 
#finalize() and auto-release.

[*] You can also exhaust the iterator by always iterating to the end, 
which will also trigger a fast release of any DB-resources (including 
ResultSet and thus implicitly Connection) when the iterator reaches the end.

It could be because of constructs like:
while (ojbiter.hasNext()) {
ojbiter.next();
if (condition) {
break out; == late release, did not exhaust iterator
}
}
Or:
ojbiter = broker.getReportQueryIteratorByCriteria(crit);
Object onlyOneExpected = ojbiter.next();
// late release, did not exhaust iterator
If you are using Oracle it should become obvious very fast if you have 
delayed release of resources in some Iterator objects, as this will keep 
the Oracle server-side cursors allocated and you will very fast get an 
SQLException with MAX_CURSORS_EXCEEDED.

Any more suggestions?
You could also try using the abandoned-config in DBCP and set a very 
short threshold time to log connection leaks, although it's difficult to 
say what the threshold should be if you really want to hold on to some 
connections a bit longer.

Regards,
 Martin
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


How to shutdown OJB when stopping web context.

2005-03-23 Thread Nathan Smith
Hi all,

I am looked through the source code, through the archives and searched the
OJB site http://db.apache.org/ojb/, but I can still not figure out how OJB
is shutdown.

We have a very serious problem with our connection pool at the moment. Part
of that is to do with the connection pool that OJB uses and how it is shut
down. At the moment when I stop our web application context through the
Tomcat Manager it shuts down cleanly. The application's connection pool
shutdown method is called and all connections are closed. The OJB connection
pool is leaving connections open. Once Tomcat is stopped all connections are
closed as indicated by the Database monitor.

I would like for all connections to be closed when our web context is
stopped. How can this be done for OJB?

Any help greatly appreciated.




Nathan Smith
Software Developer
LabPro 2000 Limited
Phone: +64 4 586 6840
Facsimile: +64 4 586 6841
[EMAIL PROTECTED]
www.labpro2000.com
Level 6, Riverside Tower on Daly, 15 Daly Street
Lower Hutt, New Zealand 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to shutdown OJB when stopping web context.

2005-03-23 Thread Alexandre Borgoltz
Nathan,
I can see you aren't getting any answer for a few hours so I'll dare my 
own hint...

Maybe you could have OJB use a container-provided datasource instead.
For this, use jndi-datasource-name instead of 
dbalias/driver/user/password/protocol/subprotocol in your 
jdbc-connection-descriptor /
http://db.apache.org/ojb/docu/guides/repository.html#jndi-datasource-name

For example, your jdbc-connection-descriptor could look like (This is 
for Oracle, change plaform, driver and url if needed)

jdbc-connection-descriptor batch-mode=true 
ignoreAutoCommitExceptions=true jcd-alias=my-alias jdbc-level=3.0 
jndi-datasource-name=java:comp/env/jdbc/my-datasource platform=Oracle
   sequence-manager 
className=org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl
   attribute attribute-name=grabSize 
attribute-value=20/
   /sequence-manager
/jdbc-connection-descriptor

And the declaration of the webapp's context in tomcat 4 (server.xml or 
separate file) is

Context path=/MyWebApp reloadable=true docBase=MyWebApp
   Resource name=jdbc/my-datasource auth=Container 
type=javax.sql.DataSource/
   ResourceParams name=jdbc/my-datasource
 parameter
   namefactory/name
   valueorg.apache.commons.dbcp.BasicDataSourceFactory/value
 /parameter
 parameter
   namedriverClassName/name
   valueoracle.jdbc.driver.OracleDriver/value
 /parameter 
 parameter
   nameurl/name
   valuejdbc:oracle:thin:@hostname:1521:SID/value
 /parameter
 parameter
   nameusername/name
   valuefoo/value
 /parameter
 parameter
   namepassword/name
   valuebar/value
 /parameter
 parameter
   namemaxActive/name
   value20/value
 /parameter
 parameter
   namemaxIdle/name
   value10/value
 /parameter
 parameter
   namemaxWait/name
   value-1/value
 /parameter
   /ResourceParams 
/Context

In tomcat 5 it should look like:
Context path=/MyWebApp reloadable=true docBase=MyWebApp
   Resource
   name=jdbc/my-datasource
   auth=Container
   type=javax.sql.DataSource
   factory=rg.apache.commons.dbcp.BasicDataSourceFactory
   driverClassName=oracle.jdbc.driver.OracleDriver
   url=jdbc:oracle:thin:@hostname:1521:SID
   username=foo
   password=bar
   maxActive=20
   maxIdle=10
   maxWait=-1 /
/Context
This works great for me. Hope it helps.
Alexandre BORGOLTZ
Head of Technology
SmartJog SA
Phone: +33 (0)1 4996 6324
Fax: +33 (0)1 4996 6405
Mobile: +33 (0)6 8882 1417
[EMAIL PROTECTED]

Nathan Smith wrote:
Hi all,
I am looked through the source code, through the archives and searched the
OJB site http://db.apache.org/ojb/, but I can still not figure out how OJB
is shutdown.
We have a very serious problem with our connection pool at the moment. Part
of that is to do with the connection pool that OJB uses and how it is shut
down. At the moment when I stop our web application context through the
Tomcat Manager it shuts down cleanly. The application's connection pool
shutdown method is called and all connections are closed. The OJB connection
pool is leaving connections open. Once Tomcat is stopped all connections are
closed as indicated by the Database monitor.
I would like for all connections to be closed when our web context is
stopped. How can this be done for OJB?
Any help greatly appreciated.

Nathan Smith
Software Developer
LabPro 2000 Limited
Phone: +64 4 586 6840
Facsimile: +64 4 586 6841
[EMAIL PROTECTED]
www.labpro2000.com
Level 6, Riverside Tower on Daly, 15 Daly Street
Lower Hutt, New Zealand 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: How to shutdown OJB when stopping web context.

2005-03-23 Thread Charles Anthony
Alternatively, either in one of your Servlets destroy methods (or via webapp
context listener, or however you currently do your shutdown logic) get the
connection factory and invoke the releaseAllResources method

http://db.apache.org/ojb/api/org/apache/ojb/broker/accesslayer/ConnectionFac
tory.html#releaseAllResources()

e.g.

ConnectionFactoryFactory.getInstance().createFactory().releaseAllResources()
;

Cheers 

Charles


-Original Message-
From: Alexandre Borgoltz [mailto:[EMAIL PROTECTED]
Sent: 24 March 2005 07:27
To: OJB Users List
Subject: Re: How to shutdown OJB when stopping web context.


Nathan,

I can see you aren't getting any answer for a few hours so I'll dare my 
own hint...

Maybe you could have OJB use a container-provided datasource instead.

For this, use jndi-datasource-name instead of 
dbalias/driver/user/password/protocol/subprotocol in your 
jdbc-connection-descriptor /
http://db.apache.org/ojb/docu/guides/repository.html#jndi-datasource-name

For example, your jdbc-connection-descriptor could look like (This is 
for Oracle, change plaform, driver and url if needed)

jdbc-connection-descriptor batch-mode=true 
ignoreAutoCommitExceptions=true jcd-alias=my-alias jdbc-level=3.0 
jndi-datasource-name=java:comp/env/jdbc/my-datasource platform=Oracle
sequence-manager 
className=org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl
attribute attribute-name=grabSize 
attribute-value=20/
/sequence-manager
/jdbc-connection-descriptor

And the declaration of the webapp's context in tomcat 4 (server.xml or 
separate file) is

Context path=/MyWebApp reloadable=true docBase=MyWebApp
Resource name=jdbc/my-datasource auth=Container 
type=javax.sql.DataSource/
ResourceParams name=jdbc/my-datasource
  parameter
namefactory/name
valueorg.apache.commons.dbcp.BasicDataSourceFactory/value
  /parameter
  parameter
namedriverClassName/name
valueoracle.jdbc.driver.OracleDriver/value
  /parameter 
  parameter
nameurl/name
valuejdbc:oracle:thin:@hostname:1521:SID/value
  /parameter
  parameter
nameusername/name
valuefoo/value
  /parameter
  parameter
namepassword/name
valuebar/value
  /parameter
  parameter
namemaxActive/name
value20/value
  /parameter
  parameter
namemaxIdle/name
value10/value
  /parameter
  parameter
namemaxWait/name
value-1/value
  /parameter
/ResourceParams 
/Context

In tomcat 5 it should look like:

Context path=/MyWebApp reloadable=true docBase=MyWebApp
Resource
name=jdbc/my-datasource
auth=Container
type=javax.sql.DataSource
factory=rg.apache.commons.dbcp.BasicDataSourceFactory
driverClassName=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@hostname:1521:SID
username=foo
password=bar
maxActive=20
maxIdle=10
maxWait=-1 /
/Context

This works great for me. Hope it helps.

Alexandre BORGOLTZ
Head of Technology

SmartJog SA
Phone: +33 (0)1 4996 6324
Fax: +33 (0)1 4996 6405
Mobile: +33 (0)6 8882 1417
[EMAIL PROTECTED]



Nathan Smith wrote:

Hi all,

I am looked through the source code, through the archives and searched the
OJB site http://db.apache.org/ojb/, but I can still not figure out how OJB
is shutdown.

We have a very serious problem with our connection pool at the moment. Part
of that is to do with the connection pool that OJB uses and how it is shut
down. At the moment when I stop our web application context through the
Tomcat Manager it shuts down cleanly. The application's connection pool
shutdown method is called and all connections are closed. The OJB
connection
pool is leaving connections open. Once Tomcat is stopped all connections
are
closed as indicated by the Database monitor.

I would like for all connections to be closed when our web context is
stopped. How can this be done for OJB?

Any help greatly appreciated.




Nathan Smith
Software Developer
LabPro 2000 Limited
Phone: +64 4 586 6840
Facsimile: +64 4 586 6841
[EMAIL PROTECTED]
www.labpro2000.com
Level 6, Riverside Tower on Daly, 15 Daly Street
Lower Hutt, New Zealand 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

  



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



___
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com