473,809 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exiting a Class Without Exiting Java

I have a class that is sometimes called from the command line and sometimes
from another class.

When the user clicks "Quit" on the panel it opens, if it is running from the
command line, it quits. The problem is that I need a way to terminate the
class and the object without using quit, so it doesn't kill other classes.
The QUIT button calls an actionListener, so if I have "return" in the
listener, it closes the window, but the class is still active.

How can I return from the class (does that makes sense) and get the object
made from this class to "self destruct" without exiting the JVM?

Thanks!

Hal
Jul 17 '05 #1
2 3046
Hal Vaughan wrote:
I have a class that is sometimes called from the command line and sometimes
from another class.

When the user clicks "Quit" on the panel it opens, if it is running from the
command line, it quits. The problem is that I need a way to terminate the
class and the object without using quit, so it doesn't kill other classes.
The QUIT button calls an actionListener, so if I have "return" in the
listener, it closes the window, but the class is still active.

How can I return from the class (does that makes sense) and get the object
made from this class to "self destruct" without exiting the JVM?


It is a lot easier to discuss with concrete names, so let ServiceClass
be the class providing the service and ClientClass be the class invoking
ServiceClass.

Depending on your threading needs, try the following:

1) Register a callback object in the ServiceClass that it can invoke
when it is done,
2) Call notify() on an agreed upon object (perhaps even the instance of
ServiceClass itself) when ServiceClass is finished.

When the ServiceClass is finished, it notifies the ClientClass in one of
the above ways. Then you can clean up ServiceClass in the appropriate
manner. (E.g., call dispose() on Swing components, set all references
to ServiceClass to null, etc.)

Another potential solution is to use a modal dialog window. The thread
invoking show() on a modal dialog window will block until the window is
hidden. If this is appropriate for your environment, go for it.

Ray
Jul 17 '05 #2
Thanks for giving me a few good ideas to think about!

Hal

Raymond DeCampo wrote:
Hal Vaughan wrote:
I have a class that is sometimes called from the command line and
sometimes from another class.

When the user clicks "Quit" on the panel it opens, if it is running from
the
command line, it quits. The problem is that I need a way to terminate
the class and the object without using quit, so it doesn't kill other
classes. The QUIT button calls an actionListener, so if I have "return"
in the listener, it closes the window, but the class is still active.

How can I return from the class (does that makes sense) and get the
object made from this class to "self destruct" without exiting the JVM?


It is a lot easier to discuss with concrete names, so let ServiceClass
be the class providing the service and ClientClass be the class invoking
ServiceClass.

Depending on your threading needs, try the following:

1) Register a callback object in the ServiceClass that it can invoke
when it is done,
2) Call notify() on an agreed upon object (perhaps even the instance of
ServiceClass itself) when ServiceClass is finished.

When the ServiceClass is finished, it notifies the ClientClass in one of
the above ways. Then you can clean up ServiceClass in the appropriate
manner. (E.g., call dispose() on Swing components, set all references
to ServiceClass to null, etc.)

Another potential solution is to use a modal dialog window. The thread
invoking show() on a modal dialog window will block until the window is
hidden. If this is appropriate for your environment, go for it.

Ray


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
105849
by: Dave | last post by:
Hi, I have done some research, trying to Clear The Screen in java code. The first option was the obv: system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n"); then i heard about this method: System.out.print((char)27 + "[2J");
4
8037
by: Neil Zanella | last post by:
Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned in "Learning Python" by Mark Lutz and David Ascher. It seems like they are a relatively new feature... It seems to me that any truly OO programming language should support these so I'm sure that Python is no exception, but how can these be...
50
6392
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong def foo(self, data): self.attr1=data self.attr2.append(data) The initialization of attr1 is obviously OK, all instances of Father redefine it in the method foo. But the initialization of attr2 is wrong
4
8054
by: orangepic333 | last post by:
Could someone tell me what's the difference between the two? Is it that a class is used within an OO language while a component can be exported between OO languages? Are there other differences?
5
1626
by: Tim Clacy | last post by:
When exiting function scope, which occurs first: a) destruction of local objects b) copy of value for return From disassembly of a debug target, it looks like the return value is copied before local objects are destroyed. Is this standard behaviour? Can the same behaviour be expected for any optimisation level? As an example, in the function 'int A::fn()' here, is 'b' destroyed before 'i' is copied or vice-versa?:
39
2643
by: vineoff | last post by:
If I'm having nested loops like: for (...) for (..) for (...) { /* exit here */ } and I need to exit from there ^ . Is it better to use exceptions or goto or some other method?
7
4005
by: David Elliott | last post by:
I have created an application that will dynamically load other DLLs (plugins). The new plugin is a winform with an embedded IE Browser. I am wanting to have the form to run in its own thread. This would allow for other plugins and the main application to be free to do other work. I have written a little TestDriver for the plugin and am having some difficulty. If I don't use threads everything works just fine. If I do use threads, upon...
12
5933
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it says: usage: java fit.FitServer host port socketTicket -v verbose I think this is because I do not understand the jython mechanism for inheritance (yet).
6
2146
by: jmarcrum | last post by:
Hi everyone! I'm using a super class (DVD.java) that handles another class (EnhancedDVD.java). I want to pass the "details" of the DVD into the super class DVD.java. The super class contains the Title, RegionCode, Format, and Length of a dummy DVD...let's say..."Forrest Gump." But I can't figure out how to do this and I have 4 errors going on when I compile the two classes. I have a driver that runs the System.out.println's. But I think...
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10643
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.