You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by eugenebalt <eu...@yahoo.com> on 2011/07/26 03:12:01 UTC

How to Catch WebApplication's Destroy()?

I have a DB connection that I initialize on WebApplication.init(), which I
override.

At the end, I need to close the DB connection in something like a destroy
method for the app, but I couldn't find any overridable method for that. I
tried overriding sessionDestroy() but it's not getting called when I close
my browser, according to my debug statements.

So what's the way to close DB connections at the end of the Wicket app's
lifecycle? Thanks.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-Catch-WebApplication-s-Destroy-tp3694556p3694556.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to Catch WebApplication's Destroy()?

Posted by jcgarciam <jc...@gmail.com>.
Why not use a ServletContextListener
http://download.oracle.com/javaee/5/api/javax/servlet/ServletContextListener.html

Instead of using wicket for that?

On Mon, Jul 25, 2011 at 10:34 PM, eugenebalt [via Apache Wicket] <
ml-node+3694614-1673249323-65838@n4.nabble.com> wrote:

> To clarify, this is not per-request, it should be per-application.
>
> I have a static Connection object in my WebApplication, and it's used for
> all transactions in the app. I construct it initially in the init(), and was
> just wondering where to close the Connection at the end of the app.
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-wicket.1842946.n4.nabble.com/How-to-Catch-WebApplication-s-Destroy-tp3694556p3694614.html
>  To start a new topic under Apache Wicket, email
> ml-node+1842946-398011874-65838@n4.nabble.com
> To unsubscribe from Apache Wicket, click here<http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1842946&code=amNnYXJjaWFtQGdtYWlsLmNvbXwxODQyOTQ2fDEyNTYxMzc3ODY=>.
>
>



-- 

JC


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-Catch-WebApplication-s-Destroy-tp3694556p3694654.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to Catch WebApplication's Destroy()?

Posted by Martin Grigorov <mg...@apache.org>.
Actually by Servlet specification a Servlet/Filter can be destroyed at
any time without destroying the ServletContext and later re-inited
again.
That means Application#init()/destroy() can be called without
re-start/re-deploy of the application.

On Tue, Jul 26, 2011 at 11:13 AM, Miroslav F. <mi...@seznam.cz> wrote:
> As I understand it's called when app is undeployed or servlet container
> (Tomcat, Jetty,...)
> is going down. And it should be very long time after app is started.
>
>
>> -----Original Message-----
>> From: Martin Grigorov [mailto:mgrigorov@apache.org]
>> Sent: Tuesday, 26. July 2011 08:21
>> To: users@wicket.apache.org
>> Subject: Re: How to Catch WebApplication's Destroy()?
>>
>> org.apache.wicket.Application.onDestroy()
>>
>> On Tue, Jul 26, 2011 at 4:34 AM, eugenebalt
>> <eu...@yahoo.com> wrote:
>> > To clarify, this is not per-request, it should be per-application.
>> >
>> > I have a static Connection object in my WebApplication, and
>> it's used
>> > for all transactions in the app. I construct it initially in the
>> > init(), and was just wondering where to close the
>> Connection at the end of the app.
>> >
>> > --
>> > View this message in context:
>> >
>> http://apache-wicket.1842946.n4.nabble.com/How-to-Catch-WebApplication
>> > -s-Destroy-tp3694556p3694614.html Sent from the Users forum mailing
>> > list archive at Nabble.com.
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to Catch WebApplication's Destroy()?

Posted by Peter Ertl <pe...@gmx.org>.
1. I would recommend to use a connection pool, e.g. 'bonecp', 'c3p0' or 'dbcp' instead of a single connection. Using a single connection that stays connected to the db is a bad thing. You usually have to restart your web application when the database gets restarted (or goes offline for some time).
2. You can manage the lifetime of your pool using a web application factory, too. Use org.apache.wicket.protocol.http.IDestroyableWebApplicationFactory instead of org.apache.wicket.protocol.http.IWebApplicationFactory to handle destruction of the resource in method IDestroyableWebApplicationFactory#destroy().

Am 26.07.2011 um 08:21 schrieb Martin Grigorov:

> org.apache.wicket.Application.onDestroy()
> 
> On Tue, Jul 26, 2011 at 4:34 AM, eugenebalt <eu...@yahoo.com> wrote:
>> To clarify, this is not per-request, it should be per-application.
>> 
>> I have a static Connection object in my WebApplication, and it's used for
>> all transactions in the app. I construct it initially in the init(), and was
>> just wondering where to close the Connection at the end of the app.
>> 
>> --
>> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-Catch-WebApplication-s-Destroy-tp3694556p3694614.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
> 
> 
> 
> -- 
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: How to Catch WebApplication's Destroy()?

Posted by "Miroslav F." <mi...@seznam.cz>.
As I understand it's called when app is undeployed or servlet container
(Tomcat, Jetty,...)
is going down. And it should be very long time after app is started.


> -----Original Message-----
> From: Martin Grigorov [mailto:mgrigorov@apache.org] 
> Sent: Tuesday, 26. July 2011 08:21
> To: users@wicket.apache.org
> Subject: Re: How to Catch WebApplication's Destroy()?
> 
> org.apache.wicket.Application.onDestroy()
> 
> On Tue, Jul 26, 2011 at 4:34 AM, eugenebalt 
> <eu...@yahoo.com> wrote:
> > To clarify, this is not per-request, it should be per-application.
> >
> > I have a static Connection object in my WebApplication, and 
> it's used 
> > for all transactions in the app. I construct it initially in the 
> > init(), and was just wondering where to close the 
> Connection at the end of the app.
> >
> > --
> > View this message in context: 
> > 
> http://apache-wicket.1842946.n4.nabble.com/How-to-Catch-WebApplication
> > -s-Destroy-tp3694556p3694614.html Sent from the Users forum mailing 
> > list archive at Nabble.com.
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> 
> 
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to Catch WebApplication's Destroy()?

Posted by Martin Grigorov <mg...@apache.org>.
org.apache.wicket.Application.onDestroy()

On Tue, Jul 26, 2011 at 4:34 AM, eugenebalt <eu...@yahoo.com> wrote:
> To clarify, this is not per-request, it should be per-application.
>
> I have a static Connection object in my WebApplication, and it's used for
> all transactions in the app. I construct it initially in the init(), and was
> just wondering where to close the Connection at the end of the app.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-Catch-WebApplication-s-Destroy-tp3694556p3694614.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to Catch WebApplication's Destroy()?

Posted by eugenebalt <eu...@yahoo.com>.
To clarify, this is not per-request, it should be per-application.

I have a static Connection object in my WebApplication, and it's used for
all transactions in the app. I construct it initially in the init(), and was
just wondering where to close the Connection at the end of the app.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-Catch-WebApplication-s-Destroy-tp3694556p3694614.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: RE: How to Catch WebApplication's Destroy()?

Posted by "Miroslav F." <mi...@seznam.cz>.
will be next level ;-) - at current status of learning wicket framework is
better
to know how thinks works and do it myself.

 

> -----Original Message-----
> From: Josh Kamau [mailto:joshnet2030@gmail.com] 
> Sent: Tuesday, 26. July 2011 06:51
> To: users@wicket.apache.org
> Subject: Re: RE: How to Catch WebApplication's Destroy()?
> 
> are you prohibited from using a DI framework such as guice or 
> spring?  it can help you manage your object scope and lifecycle
> 
> On 26 Jul 2011 07:41, "Miroslav F." <mi...@seznam.cz> wrote:
> 
> Bad. Wicket application start when you deploy it into Tomcat 
> (it's time when
> WebApplication.init() is
> executed) and stop when you undeploy it or when you stop 
> Tomcat - it should be very long time ;-)
> 
> My scenario is: In WebPage class i do 
> LoadableDetachableModel.load() and here I load all data what 
> I need from database and do all DB stufs - open connection, 
> run SQL, close connection.
> 
> 
> 
> > -----Original Message-----
> > From: eugenebalt [mailto:eugenebalt@yahoo.com]
> > Sent: Tuesday, 2...
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: RE: How to Catch WebApplication's Destroy()?

Posted by Josh Kamau <jo...@gmail.com>.
are you prohibited from using a DI framework such as guice or spring?  it
can help you manage your object scope and lifecycle

On 26 Jul 2011 07:41, "Miroslav F." <mi...@seznam.cz> wrote:

Bad. Wicket application start when you deploy it into Tomcat (it's time when
WebApplication.init() is
executed) and stop when you undeploy it or when you stop Tomcat - it should
be very long time ;-)

My scenario is: In WebPage class i do LoadableDetachableModel.load() and
here I load all data what I need
from database and do all DB stufs - open connection, run SQL, close
connection.



> -----Original Message-----
> From: eugenebalt [mailto:eugenebalt@yahoo.com]
> Sent: Tuesday, 2...

RE: How to Catch WebApplication's Destroy()?

Posted by "Miroslav F." <mi...@seznam.cz>.
Bad. Wicket application start when you deploy it into Tomcat (it's time when
WebApplication.init() is
executed) and stop when you undeploy it or when you stop Tomcat - it should
be very long time ;-)

My scenario is: In WebPage class i do LoadableDetachableModel.load() and
here I load all data what I need
from database and do all DB stufs - open connection, run SQL, close
connection.
 

> -----Original Message-----
> From: eugenebalt [mailto:eugenebalt@yahoo.com] 
> Sent: Tuesday, 26. July 2011 03:12
> To: users@wicket.apache.org
> Subject: How to Catch WebApplication's Destroy()?
> 
> I have a DB connection that I initialize on 
> WebApplication.init(), which I override.
> 
> At the end, I need to close the DB connection in something 
> like a destroy method for the app, but I couldn't find any 
> overridable method for that. I tried overriding 
> sessionDestroy() but it's not getting called when I close my 
> browser, according to my debug statements.
> 
> So what's the way to close DB connections at the end of the 
> Wicket app's lifecycle? Thanks.
> 
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/How-to-Catch-WebApp
> lication-s-Destroy-tp3694556p3694556.html
> Sent from the Users forum mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org