Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java AWT Toolkit

  • 27-07-2000 5:04pm
    #1
    Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭


    For some reason, when I call Toolkit.getDefaultToolkit() in an application(in order to use its getImage() method to load an image), it won't exit when it reaches the end. It'll just hang there, and not exit properly. Has anyone else ever seen this problem?
    I'm using JDK 1.2.2.


Comments

  • Moderators, Social & Fun Moderators Posts: 10,501 Mod ✭✭✭✭ecksor


    Originally posted by Jazz:
    For some reason, when I call Toolkit.getDefaultToolkit() in an application(in order to use its getImage() method to load an image), it won't exit when it reaches the end. It'll just hang there, and not exit properly. Has anyone else ever seen this problem?
    I'm using JDK 1.2.2.

    Um, not sure if I understand the question.
    Do you mean that the program won't exit when you reach the end of your code? If this is the case, then the problem is probably the fact that an Java AWT Application is has more than one thread, and all of these need to end before the application can end.

    Try calling System.exit(0) when you want your code to exit.


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Yeah I went to Sun's knowledge base, and it's actually a documented bug. If you call Toolkit.getDefaultToolkit(), then main() fails to exit. The workaround they give is, as you say, to call System.exit().

    I'd already tried this, but my problem is that I'm calling getDefaultToolkit() from a servlet, and calling System.exit() from a servlet actually stops the server too.

    I'm hoping that even though main() doesn't exit, it doesn't suck up any extra system resources. If it does, eventually after calling this servlet a few hundred/thousand times it'll bring the server to its knees, and that's what I'm trying to avoid.


  • Registered Users, Registered Users 2 Posts: 332 ✭✭spod


    if main() doesn't terminate, there are still gonna be references to any objects you instantiate.

    Javas garbage collection mechanism doesn't delete objects until they are no longer referenced. Ok, it's alot more complex then that, but basically, if stuff which references objects is still lying around then they're not gonna get garbage collected. So they're sitll gonna consume resources in the jvm, which equates to resources on your machine.

    Make sure and hammer the thing *alot* to test it. If you really have to go with the solution then shutting down and re-starting your servlet engine every few days would be a good idea probably...

    messy problem frown.gif


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Yeah that's the problem I'm talking about.
    I'm setting all objects =null and then calling System.gc() at the end, that should help a little.

    Still, what a pain in the ass.


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Well I'm not 100% sure that it happens with servlets too, but when you run a normal application with a getDefaultToolkit() call in it, it doesn't return to the command line when the program finishes.
    Eg:
    public static void main(String args[]){
    Toolkit t=Toolkit.getDefaultToolkit();
    }

    Here's what the bug report on java.sun.com's bug database says (Bug ID 4031168):

    "This bug was found by St.Petersburg Java SQE team (by Dmitry A. Silaev).

    If method java.awt.Toolkit.getDefaultToolkit is called inside of 'main' body, finishing 'main' does not return to system prompt.
    System.exit, however, works fine in this case."


  • Advertisement
  • Moderators, Social & Fun Moderators Posts: 10,501 Mod ✭✭✭✭ecksor


    Originally posted by Jazz:

    Here's what the bug report on java.sun.com's bug database says (Bug ID 4031168):

    "This bug was found by St.Petersburg Java SQE team (by Dmitry A. Silaev).

    If method java.awt.Toolkit.getDefaultToolkit is called inside of 'main' body, finishing 'main' does not return to system prompt.
    System.exit, however, works fine in this case."

    It just seems to me that this is because it's running other threads, not because main() is hanging. System.exit() kills all threads, which is why you can't use it smile.gif


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Makes Sense. So how do I get at the thread running the toolkit?


  • Moderators, Social & Fun Moderators Posts: 10,501 Mod ✭✭✭✭ecksor


    Originally posted by spod:
    if main() doesn't terminate, there are still gonna be references to any objects you instantiate.

    I wrote a long reply to this on Friday evening, but it didn't get submitted because our connection b0rked ...
    Anyway, what I'm unclear is, how do you know that main() isn't exiting? I was under the impression that it was other threads that were running. Am I missing something about servlets?


Advertisement