digitalmars.D.learn - Any application shutdown hooks?
- Matthew Ong (13/13) May 25 2011 Hi,
- Steven Schveighoffer (2/2) May 25 2011 http://www.digitalmars.com/d/2.0/class.html#StaticDestructor
- Matthew Ong (15/17) May 25 2011 Static Destructor maybe executed when the class is being unloaded GC?
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (8/15) May 25 2011 There is a problem at Digital Mars's site. Steve must have meant the
- Steven Schveighoffer (7/22) May 25 2011 Oh, yeah, that's exactly what I did! hm...
- Steven Schveighoffer (9/18) May 25 2011 This is *exactly* what static destructors do.
- Matthew Ong (10/16) May 25 2011 Module Destructor: Cool feature that I can consider to use for other
- Steven Schveighoffer (9/27) May 25 2011 I should clarify that when I wrote this, I thought the description was
- Andrej Mitrovic (3/6) May 25 2011 I saw some commits change a static dtor to a shared static dtor and
- Matthew Ong (5/11) May 25 2011 Thanks a lot for the all the comments and instructions shown here.
- Matthew Ong (8/16) May 26 2011 Perhaps writing a mixin at module where the main method is located will
Hi, If I am writing a database library such as DSL, Data Service Layer, there is a need for me to do a good clean up for the connections/results sets/transactions that this library is currently handling. How ever, if another library/package somewhere else calls for a java.lang.Runtime#public void addShutdownHook(Thread hook) How do code or what library to use? can someone please provide a simple working D example for try out. Of cause, in Even in Java there is event if some cleaning lady were to accidentally unplug the main socket of your server. :) -- Matthew Ong email: ongbp yahoo.com
May 25 2011
http://www.digitalmars.com/d/2.0/class.html#StaticDestructor -Steve
May 25 2011
On 5/25/2011 11:13 PM, Steven Schveighoffer wrote:http://www.digitalmars.com/d/2.0/class.html#StaticDestructor -SteveStatic Destructor maybe executed when the class is being unloaded GC? Because this is a class level. It is more like the application level exit and such. That is not really the same as: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29 This is triggered when: when the exit (equivalently, System.exit) method is invoked, or such as typing ^C, or a system-wide event, such as user logoff or system shutdown. -- Matthew Ong email: ongbp yahoo.com
May 25 2011
On 05/25/2011 08:35 AM, Matthew Ong wrote:On 5/25/2011 11:13 PM, Steven Schveighoffer wrote:There is a problem at Digital Mars's site. Steve must have meant the module static destructor. Search for "Static Construction and Destruction" on the module page: http://www.digitalmars.com/d/2.0/module.html (Do not click StaticDestructor at the top of the page. That is linked to the class page.) Alihttp://www.digitalmars.com/d/2.0/class.html#StaticDestructor -SteveStatic Destructor maybe executed when the class is being unloaded GC? Because this is a class level. It is more like the application level exit and such.
May 25 2011
On Wed, 25 May 2011 11:50:16 -0400, Ali Çehreli <acehreli yahoo.com> wrote:On 05/25/2011 08:35 AM, Matthew Ong wrote:Oh, yeah, that's exactly what I did! hm... Need to file a bug. (filed as http://d.puremagic.com/issues/show_bug.cgi?id=6055 ) Note that class static dtors are exactly the same as module static dtors, they just are inside the class namespace. -SteveOn 5/25/2011 11:13 PM, Steven Schveighoffer wrote:There is a problem at Digital Mars's site. Steve must have meant the module static destructor. Search for "Static Construction and Destruction" on the module page: http://www.digitalmars.com/d/2.0/module.html (Do not click StaticDestructor at the top of the page. That is linked to the class page.)http://www.digitalmars.com/d/2.0/class.html#StaticDestructor -SteveStatic Destructor maybe executed when the class is being unloaded GC? Because this is a class level. It is more like the application level exit and such.
May 25 2011
On Wed, 25 May 2011 11:35:51 -0400, Matthew Ong <ongbp yahoo.com> wrote:On 5/25/2011 11:13 PM, Steven Schveighoffer wrote:This is *exactly* what static destructors do. "A static destructor gets called on program termination" Actually, that description is inaccurate for non-shared static dtors, someone should fix that.http://www.digitalmars.com/d/2.0/class.html#StaticDestructor -SteveStatic Destructor maybe executed when the class is being unloaded GC? Because this is a class level. It is more like the application level exit and such.That is not really the same as: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29If you want a static dtor that runs on every thread shutdown, use a normal static dtor. If you want one that runs on the entire application shutdown, use a shared static dtor. -Steve
May 25 2011
On 5/25/2011 11:52 PM, Steven Schveighoffer wrote:If you want a static dtor that runs on every thread shutdown, use a normal static dtor. If you want one that runs on the entire application shutdown, use a shared static dtor. -SteveModule Destructor: Cool feature that I can consider to use for other purpose.If you want one that runs on the entire application shutdown, use a shared static dtor.It is more like an entire application shutdown event. So I will be placing that at the same module dtor and file as the main(string[] args) using template mixin. That might work. I will test that out. -- Matthew Ong email: ongbp yahoo.com
May 25 2011
On Wed, 25 May 2011 11:52:14 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:On Wed, 25 May 2011 11:35:51 -0400, Matthew Ong <ongbp yahoo.com> wrote:I should clarify that when I wrote this, I thought the description was from the module.html file, not the class.html file. Ali pointed out the bug in the web site. So I didn't get why you were talking about classes, sorry :) Class and module static ctor/dtors should be exactly what you are looking for. -SteveOn 5/25/2011 11:13 PM, Steven Schveighoffer wrote:This is *exactly* what static destructors do. "A static destructor gets called on program termination" Actually, that description is inaccurate for non-shared static dtors, someone should fix that.http://www.digitalmars.com/d/2.0/class.html#StaticDestructor -SteveStatic Destructor maybe executed when the class is being unloaded GC? Because this is a class level. It is more like the application level exit and such.That is not really the same as: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29If you want a static dtor that runs on every thread shutdown, use a normal static dtor. If you want one that runs on the entire application shutdown, use a shared static dtor.
May 25 2011
On 5/25/11, Steven Schveighoffer <schveiguy yahoo.com> wrote:If you want a static dtor that runs on every thread shutdown, use a normal static dtor. If you want one that runs on the entire application shutdown, use a shared static dtor.I saw some commits change a static dtor to a shared static dtor and wondered what was that all about..
May 25 2011
On 5/26/2011 12:23 AM, Andrej Mitrovic wrote:On 5/25/11, Steven Schveighoffer<schveiguy yahoo.com> wrote:Thanks a lot for the all the comments and instructions shown here. -- Matthew Ong email: ongbp yahoo.comIf you want a static dtor that runs on every thread shutdown, use a normal static dtor. If you want one that runs on the entire application shutdown, use a shared static dtor.I saw some commits change a static dtor to a shared static dtor and wondered what was that all about..
May 25 2011
If you want a static dtor that runs on every thread shutdown, use aOn 5/25/11, Steven Schveighoffer<schveiguy yahoo.com> wrote:Perhaps writing a mixin at module where the main method is located will do that exactly. others may be dll and could be unloaded and cause __dtor to be called. Will try such direction. Thanks people. -- Matthew Ong email: ongbp yahoo.comThanks a lot for the all the comments and instructions shown here.normal static dtor. If you want one that runs on the entire application shutdown, use a shared static dtor.I saw some commits change a static dtor to a shared static dtor and wondered what was that all about..
May 26 2011