Discussion:
[aspectj-users] Capturing shutdown
Eric Bodden
2005-06-02 14:18:39 UTC
Permalink
Hi.

I have been wondering if anyone here knows how to properly capture
the shutdown of a Java application.

I have been using the following:

pointcut appExit():
execution(public static void *.main(..)) &&
!cflowbelow(execution(public static void main(String[])));

This matches the execution of the outermost "main" method. With an
"after returning"-advice I wanted to capture the shutdown. However,
this does not work if "main" spawns another thread. Then the control
flow in "main" might reach the end of the method and thus trigger the
advice while another thread is still active. So I have to take care
of the threads somehow. Has anybody done something like this yet?

Cheers,
Eric
Valentin Crettaz
2005-06-02 14:44:01 UTC
Permalink
Have you tried investigating
java.lang.Runtime.addShutdownHook(java.lang.Thread)
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)

Cheers,
Val

----- Original Message -----
From: "Eric Bodden" <***@bodden.de>
To: <aspectj-***@eclipse.org>
Sent: Thursday, June 02, 2005 4:18 PM
Subject: [aspectj-users] Capturing shutdown
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi.
I have been wondering if anyone here knows how to properly capture
the shutdown of a Java application.
execution(public static void *.main(..)) &&
!cflowbelow(execution(public static void main(String[])));
This matches the execution of the outermost "main" method. With an
"after returning"-advice I wanted to capture the shutdown. However,
this does not work if "main" spawns another thread. Then the control
flow in "main" might reach the end of the method and thus trigger the
advice while another thread is still active. So I have to take care
of the threads somehow. Has anybody done something like this yet?
Cheers,
Eric
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3
iQA/AwUBQp8VP8wiFCm7RlWCEQJZzwCeLwNxhbSoNDDViVtt7Vr8z1ieeGMAmwZk
Y/CpZB/rdQ0GOUbQ67B35srm
=3XBh
-----END PGP SIGNATURE-----
_______________________________________________
aspectj-users mailing list
https://dev.eclipse.org/mailman/listinfo/aspectj-users
Eric Bodden
2005-06-02 15:13:33 UTC
Permalink
Post by Valentin Crettaz
Have you tried investigating
java.lang.Runtime.addShutdownHook(java.lang.Thread)
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#addSh
utdownHook(java.lang.Thread)
Yes, I have. Thanks for the hint. However I would really prefer a
pure AspectJ solution, since shutdown hooks are not 100% reliable
AFAIK.

Eric

- --
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University
Valentin Crettaz
2005-06-02 15:29:18 UTC
Permalink
OK, would the following pointcut be useful somewhere in your appExit
pointcut
cflow(execution(public void Thread+.run()));

Val

----- Original Message -----
From: "Eric Bodden" <***@bodden.de>
To: <aspectj-***@eclipse.org>
Sent: Thursday, June 02, 2005 5:13 PM
Subject: RE: [aspectj-users] Capturing shutdown
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Valentin Crettaz
Have you tried investigating
java.lang.Runtime.addShutdownHook(java.lang.Thread)
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#addSh
utdownHook(java.lang.Thread)
Yes, I have. Thanks for the hint. However I would really prefer a
pure AspectJ solution, since shutdown hooks are not 100% reliable
AFAIK.
Eric
- --
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3
iQA/AwUBQp8iHcwiFCm7RlWCEQKeDwCfdVhedR6wJ8e+Yy4rPXxnevzZJzoAoLPQ
eGfUn66JQg6LypcKmnp3DFB8
=5LJg
-----END PGP SIGNATURE-----
_______________________________________________
aspectj-users mailing list
https://dev.eclipse.org/mailman/listinfo/aspectj-users
Jeffrey Palm
2005-06-02 15:39:59 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Valentin Crettaz
Have you tried investigating
java.lang.Runtime.addShutdownHook(java.lang.Thread)
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#addS
h
utdownHook(java.lang.Thread)
Yes, I have. Thanks for the hint. However I would really prefer a
pure AspectJ solution, since shutdown hooks are not 100% reliable
AFAIK.
Can you give an example when they are not reliable?

addShutdownHook is the right way to do this. A vm could exit for a number
of reasons: e.g. calling System.exit, vm error, out of memory, user
break... I don't think AspectJ can capture any or at least not all of these


Jeff
--
Jeffrey Palm --> http://www.ccs.neu.edu/home/jpalm
Eric Bodden
2005-06-02 16:25:23 UTC
Permalink
Post by Jeffrey Palm
Can you give an example when they are not reliable?
I had something in mind that under certain circumstances, shutdown
hooks may not be executed. However after further reading I think I
confused this with finalizers (where this is indeed the case). So I
think shutdown hooks are indeed what I am looking for. Thanks!

Eric

- --
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University
Wes Isberg
2005-06-02 20:21:33 UTC
Permalink
A reminder to others: shutdown hooks are for VM shutdown.

If you have long-running VM but want to pick out when applications
are stopped (and/or restarted), then AspectJ still might offer the
best-available general solution.

Wes
------------Original Message------------
Date: Thu, Jun-2-2005 9:25 AM
Subject: RE: [aspectj-users] Capturing shutdown
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Jeffrey Palm
Can you give an example when they are not reliable?
I had something in mind that under certain circumstances, shutdown
hooks may not be executed. However after further reading I think I
confused this with finalizers (where this is indeed the case). So I
think shutdown hooks are indeed what I am looking for. Thanks!
Eric
- --
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3
iQA/AwUBQp8y8swiFCm7RlWCEQKikwCePSj3jmKEbUIu+JIbLDIQqzC6mWoAn1o7
x7Y0opHXdQy00UhirE/G+qwG
=zvpx
-----END PGP SIGNATURE-----
_______________________________________________
aspectj-users mailing list
https://dev.eclipse.org/mailman/listinfo/aspectj-users
hina shah
2005-06-03 05:24:10 UTC
Permalink
Hi all,
As I am totally new to AspectJ, I really don't understand the technical
talks most of u all are involved in. But am keen to be a part of it. :-)

I wanted to know of some links from where I can download AspectJ and its
docs and any other related good stuff.
I plan to start writing small programs in AspectJ to get familiarized with
the syntax.... later I plan to take up a project in AOP for my dissertation

It wud be great if u cud guide me with the same ....

Thanks in advance.

Have a nice day!!
-HINA


-----Original Message-----
From: aspectj-users-***@eclipse.org
[mailto:aspectj-users-***@eclipse.org]On Behalf Of Wes Isberg
Sent: Friday, June 03, 2005 1:52 AM
To: aspectj-***@eclipse.org
Subject: RE: [aspectj-users] Capturing shutdown

A reminder to others: shutdown hooks are for VM shutdown.

If you have long-running VM but want to pick out when applications
are stopped (and/or restarted), then AspectJ still might offer the
best-available general solution.

Wes
------------Original Message------------
Date: Thu, Jun-2-2005 9:25 AM
Subject: RE: [aspectj-users] Capturing shutdown
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Jeffrey Palm
Can you give an example when they are not reliable?
I had something in mind that under certain circumstances, shutdown
hooks may not be executed. However after further reading I think I
confused this with finalizers (where this is indeed the case). So I
think shutdown hooks are indeed what I am looking for. Thanks!
Eric
- --
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3
iQA/AwUBQp8y8swiFCm7RlWCEQKikwCePSj3jmKEbUIu+JIbLDIQqzC6mWoAn1o7
x7Y0opHXdQy00UhirE/G+qwG
=zvpx
-----END PGP SIGNATURE-----
_______________________________________________
aspectj-users mailing list
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-***@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users



http://www.patni.com
World-Wide Partnerships. World-Class Solutions.
_____________________________________________________________________

This e-mail message may contain proprietary, confidential or legally
privileged information for the sole use of the person or entity to
whom this message was originally addressed. Any review, e-transmission
dissemination or other use of or taking of any action in reliance upon
this information by persons or entities other than the intended
recipient is prohibited. If you have received this e-mail in error
kindly delete this e-mail from your records. If it appears that this
mail has been forwarded to you without proper authority, please notify
us immediately at ***@patni.com and delete this mail.
_____________________________________________________________________
Eric Bodden
2005-06-03 12:09:13 UTC
Permalink
Post by Wes Isberg
A reminder to others: shutdown hooks are for VM shutdown.
If you have long-running VM but want to pick out when applications
are stopped (and/or restarted), then AspectJ still might offer the
best-available general solution.
Hmmm... I am a bit confused. So is it generally possible to run
various applications on the same VM instance, so that one application
can quit, e.g. using System.exit(..) but still no shutdown hooks are
run since another application is still running on the same VM?

Cheers,
Eric

- --
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University
Rafal Krzewski
2005-06-03 12:22:01 UTC
Permalink
Post by Eric Bodden
Hmmm... I am a bit confused. So is it generally possible to run
various applications on the same VM instance, so that one application
can quit, e.g. using System.exit(..) but still no shutdown hooks are
run since another application is still running on the same VM?
System.exit(..) causes orderly VM termination (w/ hooks etc). If an
application is designed to coexist in other applications in the save VM
it should never ever attempt to call it.

Returning from main(..) method may or may not terminate the VM depending
on the circumstances - when there active threads with non-deamon status
the VM will continue. System.exit(..) causes all threads (deamon & not)
to terminate by throwing ThreadDeath error in their current frame. A
misbehaving thread may still catch ThreadDeath, but after an attempt to
stop the applicaiton threads is made and other clean up actitities are
completed (finalizers, shutdown hooks, delete-on-exit files), the VM
will do System.abort(..).

It is also possible to call System.abort(..) directly, but it's not a
good idea under most circumstances.

Application containers usually prevent stopping the VM by application
code using java.security mechanism, so System.exit(..) is a concern only
for standalone/desktop applications.

Hope this helps
Rafal
Jeffrey Palm
2005-06-03 12:29:08 UTC
Permalink
Post by Rafal Krzewski
Returning from main(..) method may or may not terminate the VM
depending on the circumstances - when there active threads with
non-deamon status the VM will continue. System.exit(..) causes all
And you certainly don't need a main method to execute a class:

public class NoMain {
static {
System.out.println("This is my application");
System.exit(0);
}
}

Jeff
Mik Kersten
2005-06-03 14:45:09 UTC
Permalink
-----Original Message-----
...
Hi all,
As I am totally new to AspectJ, I really don't understand the
technical
talks most of u all are involved in. But am keen to be a part of it. :-)
I wanted to know of some links from where I can download AspectJ and its
docs and any other related good stuff.
I plan to start writing small programs in AspectJ to get familiarized with
the syntax.... later I plan to take up a project in AOP for my
dissertation
http://eclipse.org/aspectj

Continue reading on narkive:
Loading...