N
nukleus
I have some old java code that is having a problem when closing frames.
It is all AWT code, no javax.
The main frame class opens another frame to do actual work,
which creates a new thread to do actual work and the main object
(for this frame) behaves like a supervisor of sorts. No matter what
happens to the worker thread, you still have control of gui and can
terminate things if network connection hangs, unexpected data
arrives, etc.
The problem is this. The worker thread needs to be terminated,
which is easy enough, when user hits abort key, the event handler
sets some variable, which is tested in the main run() loop.
Then, when the main run loop terminates, it calls the Terminator()
that does dispose(). That seems to be working fine and things
close logically correct. Even if user hits Abort button in the
middle of a lengty network operation, we do not destroy the
worker frame until its thread terminates. Otherwise, after worker
frame is closed, we may still be getting log messages in the log
text area of the main frame after worker frame was destroyed,
which looks weird, we aborted the process, but still keep getting
the log messages sent by the worker thread.
The question is: is is the right approach?
The old code used to simply kill the worker thread,
which would crash the program in some situations.
Secondly, the way it is done is to create a worker frame object
when the main frame goes thru initialization phases.
The worker frame never really gets destroyed, even after we
Abort some operation. It simply gets hidden. Since worker frame
creates a separate thread to run, we have a non-blocking
dialog of worker frame that can remain open simultaneously
with the main frame and both of them do not interfere with each other.
That means, we can load the new configuration parameters
for the program and keep the worker frame open and it will
correctly display all the new parameters from a different configuration set.
The same case is with other frames performing different tasks.
Their guis are properly updated with new config info.
The drawback: since worker frame loads various archive files
of very large size and, not being actually destroyed, causes consumption
of large amount of memory, held by various vectors and buffers.
So, effectively, the garbage collection does not happen and we have to
manually free the vectors, buffers, etc. that are not needed at the moment.
If worker frame was destroyed, the whole thing with memory management
would become much simplier as all the objects, buffers and vectors
would get deallocated with next invocation of garbage collector.
So, the question is eternally the same: what to do?
On one hand, we would like this luxury of being able to see
everything simultaneously in various frames, and, on the other hand,
as long as they exist, they can potentially tie up large amounts of memory.
Does anyone have an opinion on this?
Thanks.
It is all AWT code, no javax.
The main frame class opens another frame to do actual work,
which creates a new thread to do actual work and the main object
(for this frame) behaves like a supervisor of sorts. No matter what
happens to the worker thread, you still have control of gui and can
terminate things if network connection hangs, unexpected data
arrives, etc.
The problem is this. The worker thread needs to be terminated,
which is easy enough, when user hits abort key, the event handler
sets some variable, which is tested in the main run() loop.
Then, when the main run loop terminates, it calls the Terminator()
that does dispose(). That seems to be working fine and things
close logically correct. Even if user hits Abort button in the
middle of a lengty network operation, we do not destroy the
worker frame until its thread terminates. Otherwise, after worker
frame is closed, we may still be getting log messages in the log
text area of the main frame after worker frame was destroyed,
which looks weird, we aborted the process, but still keep getting
the log messages sent by the worker thread.
The question is: is is the right approach?
The old code used to simply kill the worker thread,
which would crash the program in some situations.
Secondly, the way it is done is to create a worker frame object
when the main frame goes thru initialization phases.
The worker frame never really gets destroyed, even after we
Abort some operation. It simply gets hidden. Since worker frame
creates a separate thread to run, we have a non-blocking
dialog of worker frame that can remain open simultaneously
with the main frame and both of them do not interfere with each other.
That means, we can load the new configuration parameters
for the program and keep the worker frame open and it will
correctly display all the new parameters from a different configuration set.
The same case is with other frames performing different tasks.
Their guis are properly updated with new config info.
The drawback: since worker frame loads various archive files
of very large size and, not being actually destroyed, causes consumption
of large amount of memory, held by various vectors and buffers.
So, effectively, the garbage collection does not happen and we have to
manually free the vectors, buffers, etc. that are not needed at the moment.
If worker frame was destroyed, the whole thing with memory management
would become much simplier as all the objects, buffers and vectors
would get deallocated with next invocation of garbage collector.
So, the question is eternally the same: what to do?
On one hand, we would like this luxury of being able to see
everything simultaneously in various frames, and, on the other hand,
as long as they exist, they can potentially tie up large amounts of memory.
Does anyone have an opinion on this?
Thanks.