My program is still running when I am finished. I outputted text at the end of the main, so I know it gets there just fine and the program finished everything just fine... but the jvm is still running. How do I find out where it's still running so I can at least know specifically what's the problem? Any special programs or ideas?
Thanks,
-blazed
18 2134
You must have started threads then somewhere in your program. Make those
threads 'daemon threads' (check the API documentation) before you start them.
Daemon threads die when the main thread dies so the JVM will stop (it has
nothing more to do).
kind regards,
Jos
You must have started threads then somewhere in your program. Make those
threads 'daemon threads' (check the API documentation) before you start them.
Daemon threads die when the main thread dies so the JVM will stop (it has
nothing more to do).
kind regards,
Jos
I'm sorry, but unfortunately I have 0 experience with threads. I looked into daemon threads, but honestly, I'm not starting a new thread anywhere in the program. I also checked and closed all streams, I don't know what this could be, really.
I did find this in the class thread API:
"When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class)."
I could try to call this class from another program (which I'm planning on doing anyway) instead of using its own main... but I wonder if something will continue to run in the background.
I know of threads, and a fairly good idea of what they are and how they work. I'm wondering if whatever methods I'm calling create threads (SAX ? ). I've been using sax for a while though and never had this problem before...
Thanks for all your help,
-blazed
I'm sorry, but unfortunately I have 0 experience with threads. I looked into daemon threads, but honestly, I'm not starting a new thread anywhere in the program. I also checked and closed all streams, I don't know what this could be, really.
I did find this in the class thread API:
"When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class)."
I could try to call this class from another program (which I'm planning on doing anyway) instead of using its own main... but I wonder if something will continue to run in the background.
I know of threads, and a fairly good idea of what they are and how they work. I'm wondering if whatever methods I'm calling create threads (SAX ? ). I've been using sax for a while though and never had this problem before...
Thanks for all your help,
-blazed
May I know
1.) What your program does
2.) How you determined that the JVM is still running after your program has exited
May I know
1.) What your program does
2.) How you determined that the JVM is still running after your program has exited
Sure thing:
1) My program parses an xml file and writes to another file all the "tags" in the xml file. Tags are basically locations in which characters/data are read... It also records specific pieces of data that I will need. I haven't written it yet, but afterwards, I will read the file again after the user chooses what "tags" or data they are interested in, and then store the data into a predetermined format of bytecode.
To keep things simple, it parses the xml file and writes certain things to a file that it read. That's about it. To be even more specific, for a file that looks like this: -
<?xml version="1.0"?>
-
-
<poem xmlns="http://www.megginson.com/ns/exp/poetry">
-
<title>Roses are Red</title>
-
<l> Roses are red,</l>
-
<l>Violets are blue;</l>
-
<l>Sugar is sweet,</l>
-
<l>And I love you.</l>
-
</poem>
-
the outputted text looks look like this: -
* setDocumentLocator() called
-
Parsing begins...
-
Mapping starts for prefix mapped to URI http://www.megginson.com/ns/exp/poetry
-
Mapping ends for prefix
-
...Parsing ends.
-
-
Start gps-time(s): 0.0
-
End gps-time(s): 0.0
-
Total time(s): 0.0
-
Tags:
-
-
poem\title\
-
poem\l\
-
I actually ran the program on that file and spit out that text file.
The tags are "poem\title\" and "poem\l\".
2) I'm using JCreator and if you look on the top part there's an execute button and next to it or after a few more buttons there is a "stop" or kill button. You can't hit the execute button while it's still running and you can't hit the kill button unless something is running. When the program is finished the execute button is disabled and the kill button is able to be clicked. Unless I hit the kill button or put system.exit(number) at the end of my main it won't stop.
Here's my main just in case it'll help: -
public static void main(String args[]) {
-
-
OutputTagsXMLReader XMLReader = new OutputTagsXMLReader();
-
-
XMLReader.parseFile();
-
//I tried putting a system.out.println("text") here and printed the "text" to the screen, meaning it must be finishing the .parseFile() method and all methods along the way, right?
-
}
-
Since I don't visibly start threads along the way I'm lead to believe something else in the parser perhaps is starting a thread, but I've never ran into this problem before and have been reading these xml files for quite a bit of time now since I started working here.
Hope that answers your questions and thanks for your help,
-blazed
Sure thing:
1) My program parses an xml file and writes to another file all the "tags" in the xml file. Tags are basically locations in which characters/data are read... It also records specific pieces of data that I will need. I haven't written it yet, but afterwards, I will read the file again after the user chooses what "tags" or data they are interested in, and then store the data into a predetermined format of bytecode.
To keep things simple, it parses the xml file and writes certain things to a file that it read. That's about it. To be even more specific, for a file that looks like this: -
<?xml version="1.0"?>
-
-
<poem xmlns="http://www.megginson.com/ns/exp/poetry">
-
<title>Roses are Red</title>
-
<l> Roses are red,</l>
-
<l>Violets are blue;</l>
-
<l>Sugar is sweet,</l>
-
<l>And I love you.</l>
-
</poem>
-
the outputted text looks look like this: -
* setDocumentLocator() called
-
Parsing begins...
-
Mapping starts for prefix mapped to URI http://www.megginson.com/ns/exp/poetry
-
Mapping ends for prefix
-
...Parsing ends.
-
-
Start gps-time(s): 0.0
-
End gps-time(s): 0.0
-
Total time(s): 0.0
-
Tags:
-
-
poem\title\
-
poem\l\
-
I actually ran the program on that file and spit out that text file.
The tags are "poem\title\" and "poem\l\".
2) I'm using JCreator and if you look on the top part there's an execute button and next to it or after a few more buttons there is a "stop" or kill button. You can't hit the execute button while it's still running and you can't hit the kill button unless something is running. When the program is finished the execute button is disabled and the kill button is able to be clicked. Unless I hit the kill button or put system.exit(number) at the end of my main it won't stop.
Here's my main just in case it'll help: -
public static void main(String args[]) {
-
-
OutputTagsXMLReader XMLReader = new OutputTagsXMLReader();
-
-
XMLReader.parseFile();
-
//I tried putting a system.out.println("text") here and printed the "text" to the screen, meaning it must be finishing the .parseFile() method and all methods along the way, right?
-
}
-
Since I don't visibly start threads along the way I'm lead to believe something else in the parser perhaps is starting a thread, but I've never ran into this problem before and have been reading these xml files for quite a bit of time now since I started working here.
Hope that answers your questions and thanks for your help,
-blazed
Does it not open a console window written "press any key to continue" after execution?
Does it not open a console window written "press any key to continue" after execution?
No.
But what do you mean? Should it? Why? Do netbeans and other IDE's do that? Or are you saying my program should do that?
-blazed
No.
But what do you mean? Should it? Why? Do netbeans and other IDE's do that? Or are you saying my program should do that?
-blazed
No, different IDE's show the output on different windows. I thought you had said something about a message being printed to the screen.
I remember now that JCreator shows a console window somewhere at the bottom. What is the message printed there?
I don't like having to ask for the code ...
Just another question: do you do *anything* with AWT or Swing in your program?
kind regards,
Jos
No, different IDE's show the output on different windows. I thought you had said something about a message being printed to the screen.
I remember now that JCreator shows a console window somewhere at the bottom. What is the message printed there?
I don't like having to ask for the code ...
The message simply says this: - --------------------Configuration: <Default>--------------------
-
Finished Writing Tag Log File
Sorry, I took out that message that I said I was writing. I just wrote it to the screen at one point to verify that the program got to that stage. If I'm misunderstanding what you mean could you specify what message of mine you're referring to?
Listen, if this was shorter I would post all my code, but it's a little too much to put all on the forum. The reader class isn't that big and this is it:
Thanks for all your help and sorry for the misunderstanding,
-blazed
Got it. As I suspected (see my previous reply) you are using the AWT event
dispatcher thread (you're using a FileDialog). That thread isn't a daemon thread
so it keeps on running after the main thread died. Terminate your program with
a System.exit(<some number>) and all will be fine again.
kind regards,
Jos
Most probably the parsing is not completing then.The parse method is synchronous. see the specs for it.
Got it. As I suspected (see my previous reply) you are using the AWT event
dispatcher thread (you're using a FileDialog). That thread isn't a daemon thread
so it keeps on running after the main thread died. Terminate your program with
a System.exit(<some number>) and all will be fine again.
kind regards,
Jos
Oh, I missed that thread.
Got it. As I suspected (see my previous reply) you are using the AWT event
dispatcher thread (you're using a FileDialog). That thread isn't a daemon thread
so it keeps on running after the main thread died. Terminate your program with
a System.exit(<some number>) and all will be fine again.
kind regards,
Jos
Well, here's the thing. I want to call this class, run it, then continue running a program which will read that file, and reparse for specific data to turn it into bytecode. If I system.exit(0) won't it stop everything? I know I could just let that old file dialog run in the background, but it seems like a waste of processor? Is there a way to specifically stop this class/program from running and continue the rest?
... Am I going to have to run it as a thread and kill it when it's finished or something like that?
-blazed
Well, here's the thing. I want to call this class, run it, then continue running a program which will read that file, and reparse for specific data to turn it into bytecode. If I system.exit(0) won't it stop everything? I know I could just let that old file dialog run in the background, but it seems like a waste of processor? Is there a way to specifically stop this class/program from running and continue the rest?
... Am I going to have to run it as a thread and kill it when it's finished or something like that?
-blazed
Yep, if you System.exit(<number>) everything dies. About that AWT thread:
the thread doesn't do anything at all (read: doesn't take up cpu time) when there
are no user instigated events and nothing needs to be repainted, so you can let
it run forever. It won't stop running when your main thread dies though, hence the
System.exit(<number>).
You won't lose performance because of that (waiting) thread. It was a design
issue for the designers of AWT/Swing: either have a multi threaded GUI thing,
which is a total mess (google for that) or have a single threaded, non daemon
thread take care of it all. You don't even want to terminate that thread when your
main thread terminates, i.e. it would be nearly impossible to build GUI applications
if that were the case.
Simply let that thread wait and invoke System.exit(<number>) when your main
thread dies. If you're really paranoia about it: check the ThreadGroup an use the
(deprecated) stop() method on the AWT thread.
kind regards,
Jos
Yep, if you System.exit(<number>) everything dies. About that AWT thread:
the thread doesn't do anything at all (read: doesn't take up cpu time) when there
are no user instigated events and nothing needs to be repainted, so you can let
it run forever. It won't stop running when your main thread dies though, hence the
System.exit(<number>).
You won't lose performance because of that (waiting) thread. It was a design
issue for the designers of AWT/Swing: either have a multi threaded GUI thing,
which is a total mess (google for that) or have a single threaded, non daemon
thread take care of it all. You don't even want to terminate that thread when your
main thread terminates, i.e. it would be nearly impossible to build GUI applications
if that were the case.
Simply let that thread wait and invoke System.exit(<number>) when your main
thread dies. If you're really paranoia about it: check the ThreadGroup an use the
(deprecated) stop() method on the AWT thread.
kind regards,
Jos
Thanks a lot. I guess I'll just use the system.exit(<number>) whenever I'm completely finished...
-blazed
Thanks a lot. I guess I'll just use the system.exit(<number>) whenever I'm completely finished...
-blazed
Yup, that's the way to go or otherwise don't start up that AWT thread at all,
i.e. don't instantiate any AWT/Swing component at all. That 'setVisible()' method
is the culprit: it enqueues a repaint operation which is the job of that AWT thread.
kind regards,
Jos
Yup, that's the way to go or otherwise don't start up that AWT thread at all,
i.e. don't instantiate any AWT/Swing component at all. That 'setVisible()' method
is the culprit: it enqueues a repaint operation which is the job of that AWT thread.
kind regards,
Jos
What better way is there to ask the user what file to read or save to? Is there a way to make the file dialog appear without using setVisible? How can the AWT thread do it on it's own?
-blazed
What better way is there to ask the user what file to read or save to? Is there a way to make the file dialog appear without using setVisible? How can the AWT thread do it on it's own?
-blazed
Nothing 'appears' out of itself without making it visible first. Either bail out if the
user didn't supply the correct command line argument(s) or use a shell or command
line interface for the correct arguments or go for the whole nine yards and
supply a gui (in which case you have to System.exit()).
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Player |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello
I am teaching myself python, and I have gotten a long way, it's quite a
decent language and the syntax is great :)
However I am having a...
|
by: Cardman |
last post by:
Greetings,
I am trying to solve a problem that has been inflicting my self
created Order Forms for a long time, where the problem is that as I
cannot reproduce this error myself, then it is...
|
by: Venkat |
last post by:
I just installed Visual Studio.Net 2003 and that is
supposed to add that asp.net 1.1 extension. I got an error
message while opening ASP.NET project.Error is :
"visual studio.net has...
|
by: Rano |
last post by:
/*
Hello,
I've got some troubles with a stupid program...
In fact, I just start with the C language and sometime
I don't understand how I really have to use malloc.
I've readden the FAQ...
|
by: Niall |
last post by:
I have an unmanaged C++ ray tracer which I am working to put a C# front end
on. It runs fine as just the unmanaged code. I have made a MC++ wrapper DLL
to expose the required types to the C#...
|
by: TS |
last post by:
Im in a web page and call an asynchronous method in business class. the call
back method is in the web page.
When page processes, it runs thru code begins invoking the method then the
page...
|
by: TPJ |
last post by:
Help me please, because I really don't get it. I think it's some stupid
mistake I make, but I just can't find it. I have been thinking about it
for three days so far and I still haven't found any...
|
by: Svenn Bjerkem |
last post by:
Hi,
Armed with Programming Python 3rd Edition and Learning Python 2nd
edition I try to write an application which I at first thought was
simple, at least until I was finished with the GUI and...
|
by: naknak4 |
last post by:
Introduction
This assignment requires you to develop solutions to the given problem
using several different approaches (which actually involves using three
different STL containers). You will...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |