Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

How to allow termination of java application

Thread view: 
John Bailo - 25 Oct 2005 19:38 GMT
I wrote a java application that runs through several steps including
retrieving some records from a database and posting them to an
application server.

Occasionally I will want to stop the process midstream -- on other
occassions the state of the external servers may put the program into an
endless loop.

In that condition I am unable to kill the java.exe in Task manager
(windows 2000).

Question: Do I need to put in some type of trap or handler so that a
user can kill an application?

Is that what InterruptedException is for?

One person suggested putting Thread.Sleep(100) periodically in the loop
-- so that a termination gets a chance to be read.

Is that right?

It seems really wasteful....
Oliver Wong - 25 Oct 2005 19:58 GMT
> I wrote a java application that runs through several steps including
> retrieving some records from a database and posting them to an application
[quoted text clipped - 9 lines]
> Question: Do I need to put in some type of trap or handler so that a user
> can kill an application?

   Might not be a bad idea. If your application has some sort of GUI, you
could add a cancel button so that the user can stop the application from
doing whatever it's doing.

> Is that what InterruptedException is for?

   I doubt that killing the java.exe process in the Task Manager will
translate into an Exception getting thrown in your Java program.

> One person suggested putting Thread.Sleep(100) periodically in the loop --  
> so that a termination gets a chance to be read.
>
> Is that right?
>
> It seems really wasteful....

   If you're periodically sleeping merely to give other threads a chance,
you might want to use Thread.yield() instead. On most implementations, if no
other threads are waiting to run, Thread.yield() will immediately return and
your program will keep running. Otherwise, your thread will pause while the
other thread does its work.

   - Oliver
Roedy Green - 26 Oct 2005 05:16 GMT
>One person suggested putting Thread.Sleep(100) periodically in the loop
>-- so that a termination gets a chance to be read.
If the java.exe is so far up its a.s that you can't even kill it with
the taskmanager very unlikely any internal code will respond either.

This is a bug in the OS.  No task should be able to do that even
intentionally.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.