BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: app not reset/exit'ed correctly

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder IDE
View previous topic :: View next topic  
Author Message
Kevin Dean
Guest





PostPosted: Thu Apr 01, 2004 3:02 pm    Post subject: Re: app not reset/exit'ed correctly Reply with quote



The "Reset" button is a hard reset; it shuts down the JVM unconditionally,
so your hook won't get called. It's basically there as a last resort in
case the application won't exit normally.

--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"alan jeeves" <fake (AT) fake (DOT) com> wrote

Quote:
Hi,

In my app i have added a Shutdown Hook via
Runtime.getRuntime().addShutdownHook(thread) which works okay outside
JBuilder but is not executated when using JBuilder X to run my app and
clicking Reset to close the app.

Is there a Java or JBuilder reason for this? Is there a way to control
JBuilder when it stops applications?

Thanks
Alan.





Back to top
alan jeeves
Guest





PostPosted: Thu Apr 01, 2004 4:10 pm    Post subject: Re: app not reset/exit'ed correctly Reply with quote



Thanks but how can i shut it down nicely? Ctrl-C doesnt work and its not a
GUI application



"Kevin Dean" <NkOdSePaAnM (AT) datadevelopment (DOT) com> wrote

Quote:
The "Reset" button is a hard reset; it shuts down the JVM unconditionally,
so your hook won't get called. It's basically there as a last resort in
case the application won't exit normally.

--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"alan jeeves" <fake (AT) fake (DOT) com> wrote in message
news:406ae0a3$1 (AT) newsgroups (DOT) borland.com...
Hi,

In my app i have added a Shutdown Hook via
Runtime.getRuntime().addShutdownHook(thread) which works okay outside
JBuilder but is not executated when using JBuilder X to run my app and
clicking Reset to close the app.

Is there a Java or JBuilder reason for this? Is there a way to control
JBuilder when it stops applications?

Thanks
Alan.






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ([url]http://www.grisoft.com)[/url].
Version: 6.0.648 / Virus Database: 415 - Release Date: 31/03/2004



Back to top
Kevin Dean
Guest





PostPosted: Thu Apr 01, 2004 9:47 pm    Post subject: Re: app not reset/exit'ed correctly Reply with quote



The slightly-less-than-brute-force way is to call System.exit(0). More
correctly, an application terminates when all user threads terminate.

The main thread (the one with the "public static void main(String[] args)"
entry point) is a user thread. If your code falls through to the end of the
main() method, that thread terminates. If there are no other user threads,
your application will terminate. To try it, create a simple class as
follows:

public class TestClass {
public static void main(String[] args) {
System.out.println("Hello, world");
}
}

If you run that class, it will print the message in JBuilder's message pane
and exit immediately.

If, on the other hand, your main() method spawns other threads (e.g. to
listen for network connections) the application will linger indefinitely
because those threads likely never terminate. Those threads are more
correctly called daemon threads: they are background processes that do no
real application work until a request comes in, at which point they should
spawn another thread to handle the request and listen for the next one. In
summary:

- the entry point thread is a user thread;
- the listener thread spawned by the entry point thread is a daemon thread;
and
- the request processor threads spawned by the listener thread are user
threads.

Naturally, if the listener thread is just sitting there doing nothing, you
would like it to shut down when the application shuts down. You can
accomplish this by calling listenerThread.setDaemon(true) before starting
the thread.

Things work slightly differently for GUI applications. The GUI event thread
terminates when all windows are disposed of. To accomplish this, make sure
that every frame has its default close operation set to DISPOSE_ON_CLOSE:

myFrame1.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

You can also set the main frame to exit the application on close:

myMainFrame1.setDefaultCloseOperation(EXIT_ON_CLOSE);

but that has the unfortunately consequence of terminating any user threads
that may still be running and isn't quite as clean.
--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"alan jeeves" <fake (AT) fake (DOT) com> wrote

Quote:
Thanks but how can i shut it down nicely? Ctrl-C doesnt work and its not a
GUI application



"Kevin Dean" <NkOdSePaAnM (AT) datadevelopment (DOT) com> wrote in message
news:406c2f2a$1 (AT) newsgroups (DOT) borland.com...
The "Reset" button is a hard reset; it shuts down the JVM
unconditionally,
so your hook won't get called. It's basically there as a last resort in
case the application won't exit normally.

--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"alan jeeves" <fake (AT) fake (DOT) com> wrote in message
news:406ae0a3$1 (AT) newsgroups (DOT) borland.com...
Hi,

In my app i have added a Shutdown Hook via
Runtime.getRuntime().addShutdownHook(thread) which works okay outside
JBuilder but is not executated when using JBuilder X to run my app and
clicking Reset to close the app.

Is there a Java or JBuilder reason for this? Is there a way to control
JBuilder when it stops applications?

Thanks
Alan.






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ([url]http://www.grisoft.com)[/url].
Version: 6.0.648 / Virus Database: 415 - Release Date: 31/03/2004





Back to top
alan jeeves
Guest





PostPosted: Thu Apr 01, 2004 10:08 pm    Post subject: Re: app not reset/exit'ed correctly Reply with quote

thanks for that.

The app is indeed a server like app (how did you know? Smile and it does wait
for connections from clients.

The app closes clean (enough for me) when I run it on the command line and
press Ctrl+C but within JBuilder (like you've said) it closes the app badly.
Without me changing my code, is there anyway to config jbuilder to close it
in a similar manor as pressing Ctrl+C does?

Thanks
Alan


"Kevin Dean" <NkOdSePaAnM (AT) datadevelopment (DOT) com> wrote

Quote:
The slightly-less-than-brute-force way is to call System.exit(0). More
correctly, an application terminates when all user threads terminate.

The main thread (the one with the "public static void main(String[] args)"
entry point) is a user thread. If your code falls through to the end of
the
main() method, that thread terminates. If there are no other user
threads,
your application will terminate. To try it, create a simple class as
follows:

public class TestClass {
public static void main(String[] args) {
System.out.println("Hello, world");
}
}

If you run that class, it will print the message in JBuilder's message
pane
and exit immediately.

If, on the other hand, your main() method spawns other threads (e.g. to
listen for network connections) the application will linger indefinitely
because those threads likely never terminate. Those threads are more
correctly called daemon threads: they are background processes that do no
real application work until a request comes in, at which point they should
spawn another thread to handle the request and listen for the next one.
In
summary:

- the entry point thread is a user thread;
- the listener thread spawned by the entry point thread is a daemon
thread;
and
- the request processor threads spawned by the listener thread are user
threads.

Naturally, if the listener thread is just sitting there doing nothing, you
would like it to shut down when the application shuts down. You can
accomplish this by calling listenerThread.setDaemon(true) before starting
the thread.

Things work slightly differently for GUI applications. The GUI event
thread
terminates when all windows are disposed of. To accomplish this, make
sure
that every frame has its default close operation set to DISPOSE_ON_CLOSE:

myFrame1.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

You can also set the main frame to exit the application on close:

myMainFrame1.setDefaultCloseOperation(EXIT_ON_CLOSE);

but that has the unfortunately consequence of terminating any user threads
that may still be running and isn't quite as clean.
--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"alan jeeves" <fake (AT) fake (DOT) com> wrote in message
news:406c3edc$1 (AT) newsgroups (DOT) borland.com...
Thanks but how can i shut it down nicely? Ctrl-C doesnt work and its not
a
GUI application



"Kevin Dean" <NkOdSePaAnM (AT) datadevelopment (DOT) com> wrote in message
news:406c2f2a$1 (AT) newsgroups (DOT) borland.com...
The "Reset" button is a hard reset; it shuts down the JVM
unconditionally,
so your hook won't get called. It's basically there as a last resort
in
case the application won't exit normally.

--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"alan jeeves" <fake (AT) fake (DOT) com> wrote in message
news:406ae0a3$1 (AT) newsgroups (DOT) borland.com...
Hi,

In my app i have added a Shutdown Hook via
Runtime.getRuntime().addShutdownHook(thread) which works okay
outside
JBuilder but is not executated when using JBuilder X to run my app
and
clicking Reset to close the app.

Is there a Java or JBuilder reason for this? Is there a way to
control
JBuilder when it stops applications?

Thanks
Alan.






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ([url]http://www.grisoft.com)[/url].
Version: 6.0.648 / Virus Database: 415 - Release Date: 31/03/2004







Back to top
Kevin Dean
Guest





PostPosted: Mon Apr 05, 2004 12:33 pm    Post subject: Re: app not reset/exit'ed correctly Reply with quote

Not that I'm aware of, no. When spawning your background listener thread,
just call setDaemon(true) on the thread before starting it. You will, of
course, have to ensure that there is at least one thread (e.g. a graphical
status monitor) that is non-daemon.

--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"alan jeeves" <fake (AT) fake (DOT) com> wrote

Quote:
thanks for that.

The app is indeed a server like app (how did you know? Smile and it does wait
for connections from clients.

The app closes clean (enough for me) when I run it on the command line and
press Ctrl+C but within JBuilder (like you've said) it closes the app
badly.
Without me changing my code, is there anyway to config jbuilder to close
it
in a similar manor as pressing Ctrl+C does?

Thanks
Alan


"Kevin Dean" <NkOdSePaAnM (AT) datadevelopment (DOT) com> wrote in message
news:406c8ea8 (AT) newsgroups (DOT) borland.com...
The slightly-less-than-brute-force way is to call System.exit(0). More
correctly, an application terminates when all user threads terminate.

The main thread (the one with the "public static void main(String[]
args)"
entry point) is a user thread. If your code falls through to the end of
the
main() method, that thread terminates. If there are no other user
threads,
your application will terminate. To try it, create a simple class as
follows:

public class TestClass {
public static void main(String[] args) {
System.out.println("Hello, world");
}
}

If you run that class, it will print the message in JBuilder's message
pane
and exit immediately.

If, on the other hand, your main() method spawns other threads (e.g. to
listen for network connections) the application will linger indefinitely
because those threads likely never terminate. Those threads are more
correctly called daemon threads: they are background processes that do
no
real application work until a request comes in, at which point they
should
spawn another thread to handle the request and listen for the next one.
In
summary:

- the entry point thread is a user thread;
- the listener thread spawned by the entry point thread is a daemon
thread;
and
- the request processor threads spawned by the listener thread are user
threads.

Naturally, if the listener thread is just sitting there doing nothing,
you
would like it to shut down when the application shuts down. You can
accomplish this by calling listenerThread.setDaemon(true) before
starting
the thread.

Things work slightly differently for GUI applications. The GUI event
thread
terminates when all windows are disposed of. To accomplish this, make
sure
that every frame has its default close operation set to
DISPOSE_ON_CLOSE:

myFrame1.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

You can also set the main frame to exit the application on close:

myMainFrame1.setDefaultCloseOperation(EXIT_ON_CLOSE);

but that has the unfortunately consequence of terminating any user
threads
that may still be running and isn't quite as clean.
--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"alan jeeves" <fake (AT) fake (DOT) com> wrote in message
news:406c3edc$1 (AT) newsgroups (DOT) borland.com...
Thanks but how can i shut it down nicely? Ctrl-C doesnt work and its
not
a
GUI application



"Kevin Dean" <NkOdSePaAnM (AT) datadevelopment (DOT) com> wrote in message
news:406c2f2a$1 (AT) newsgroups (DOT) borland.com...
The "Reset" button is a hard reset; it shuts down the JVM
unconditionally,
so your hook won't get called. It's basically there as a last
resort
in
case the application won't exit normally.

--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html

BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server

Dolphin Data Development Ltd.
http://www.datadevelopment.com/

"alan jeeves" <fake (AT) fake (DOT) com> wrote in message
news:406ae0a3$1 (AT) newsgroups (DOT) borland.com...
Hi,

In my app i have added a Shutdown Hook via
Runtime.getRuntime().addShutdownHook(thread) which works okay
outside
JBuilder but is not executated when using JBuilder X to run my app
and
clicking Reset to close the app.

Is there a Java or JBuilder reason for this? Is there a way to
control
JBuilder when it stops applications?

Thanks
Alan.






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ([url]http://www.grisoft.com)[/url].
Version: 6.0.648 / Virus Database: 415 - Release Date: 31/03/2004









Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder IDE All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.