Results 1 to 16 of 16
Like Tree1Likes
  • 1 Post By jim829

Thread: Exception Handling makes GUI slow

  1. #1
    TomTom1 is offline Member
    Join Date
    Jul 2016
    Posts
    36
    Rep Power
    0

    Default Exception Handling makes GUI slow

    Hey,

    I tried to create an exception handling class for a GUI I'm building. My GUI expects cutrain signals from a server. If the connecting didn't work for any reason I want to provide a specific signal so that the GUI still works and doesn't crash. I use an AnimationTimer, that trys to get data from the server in every frame. When the connection is successful, it works fine, however, like I said when the exception happens it's so slow you basically can't to anything. Do you guys have any ideas why it is like that?

    The method, that throws the exception looks like this:
    Java Code:
        public static Map<String, double> getSignals(filter) throws RemoteException, IOException {
            try {
                RMI rmi = RMIConnect();
                Map<String,double> signals = rmi.getSignals(filter);
                return (Map<String, double>) signals;
            } catch (Exception ex) {
               exceptionHandling exception = new exceptionHandling();
               Map<String, double> list = exception.failedSignalsQuery(filter);
               return list;
            }
    
        }
    And the method in my exception class:
    Java Code:
    public class exceptionHandling {
        
        public Map<String, double> failedSignalsQuery(String filter) throws IOException {
            System.out.println("Couldn't get signals");
            HashMap<String, double> signals = new HashMap<>();
    
            double value = 0;
            String key = "No Connection";
    
            switch (filter) {
                case "Temp1_*":
                    signals.put(key, value);
                    break;
                case "Temp2_*":
                    signals.put(key, value);
                    break;
                case "Temp3_*":
                    signals.put(key, value);
                    break;
                case "Temp4_*":
                    signals.put("Temp1", value);
                    signals.put("Temp2", value);
                    signals.put("Temp3", value);
                    break;
                default:
                    throw new IllegalArgumentException("Invalid filter: " + filter);
            }
            return signals;
        }
    
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Exception Handling makes GUI slow

    when the exception happens it's so slow
    Is any of the code being executed on the EDT? That's the thread used by the JVM to update the GUI.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    TomTom1 is offline Member
    Join Date
    Jul 2016
    Posts
    36
    Rep Power
    0

    Default Re: Exception Handling makes GUI slow

    How can I check that? I can tell you that I haven't declared any threads in the GUI.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Exception Handling makes GUI slow

    How can I check that?
    Print out the name of the current thread that is executing.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    TomTom1 is offline Member
    Join Date
    Jul 2016
    Posts
    36
    Rep Power
    0

    Default Re: Exception Handling makes GUI slow

    Apparently it's the same thread in both methods: "Thread[JavaFX Application Thread,5,main]"

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Exception Handling makes GUI slow

    Why do you say "both" threads? If the same thing is printed, it would be the same thread.

    I don't know much about JavaFX or how it uses threads.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    TomTom1 is offline Member
    Join Date
    Jul 2016
    Posts
    36
    Rep Power
    0

    Default Re: Exception Handling makes GUI slow

    I said both methods, not both threads

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Exception Handling makes GUI slow

    Clearly the posted code isn't what you are running since you can't use a primitive type as a generic type.

    Java Code:
    Map<String, double> map
    would not work.

    Also, how are filters specified and why are you throwing an IO exception in your exception handling class? It seems to me
    that if the user is specifying a filter, then that should be validated prior to using it.

    Regards,
    Jim
    Last edited by jim829; 10-03-2016 at 11:37 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    TomTom1 is offline Member
    Join Date
    Jul 2016
    Posts
    36
    Rep Power
    0

    Default Re: Exception Handling makes GUI slow

    Yeah sorry, I wanted to simplify the code a little bit. Instead of a double value the Map contains a custom Object.
    But that shouldn't have anything to do with the problem.

    Good point with the IO exception, that is not necessary. The filter is not specified by the user but by the currently chosen scene in the GUI.
    Depending on that filter I get different signals from the server.
    Therefore I could also get rid of the IllegalArgumentException in the switch case, since it cannot happen.

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Exception Handling makes GUI slow

    Back to the problem at hand. You said you use an animation timer. Could that be running and possible interfering when the exception is thrown?
    What thread is running when the exception is thrown? Unfortunately, with just a few snippets of code, it will be difficult to help.

    Regards,
    Jim
    benji2505 likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  11. #11
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    6

    Default Re: Exception Handling makes GUI slow

    I am not sure what precisely is happening here, but I would try 2 things:
    1. Surround the body of your getSignals(filter) method with a platform.runLater(body here)
    2. In the start method set the default uncaught exception handler for Thread. From what I understand, the JVM does not terminate the FX Application when an uncaught error occurs.
    Java Code:
    Thread.setDefaultUncaughtExceptionHandler((t,e) -> 
             platform.runLater(()-> niceLittlePrintoutOfHickup(t,e)));
    'hope that helps.
    Last edited by benji2505; 10-04-2016 at 02:20 AM. Reason: Formatting

  12. #12
    TomTom1 is offline Member
    Join Date
    Jul 2016
    Posts
    36
    Rep Power
    0

    Default Re: Exception Handling makes GUI slow

    @jim829
    the AnimationTimer is running the whole time. So when I don't have a signal to the server it throws 60 exceptions/second.
    Maybe that's the problem. But on the other hand, when it works the AnimationTimer is also invoked 60 times/second and it works fine.
    Everything is happening in Thread[JavaFX Application Thread,5,main].

    @benji2505
    But the getSignals(filter) method is a remote method that runs on the server.
    That should not interfere with my GUI program or am I wrong?

  13. #13
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    6

    Default Re: Exception Handling makes GUI slow

    Is it? I would say try it and if it does not work we're smarter afterwards.

  14. #14
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Exception Handling makes GUI slow

    Do you need to check for exceptions while the animation timer is running? In other words, can you wait until you have an exception free
    session to start the timer? Or can you quickly disable the timer when the first exception is thrown?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  15. #15
    TomTom1 is offline Member
    Join Date
    Jul 2016
    Posts
    36
    Rep Power
    0

    Default Re: Exception Handling makes GUI slow

    Ok I just found out something odd. Like I said, the getSignals()-Method is a remote method, which runs under a different program.
    If I don't open this program and start my actual GUI it gets slow. However, if the server GUI is opened, but doesn't produce a valid signal I also get an exception in my GUI.
    But here, the program runs in normal speed.

    @benji, I' gonna try what you suggested

    @jim, I need to check for signals while the animation timer is running. If there is a problem I run in the exception.
    I probably could disable the timer when an exception is thrown. But then I can't check whether there is a valid signal at a later point.

  16. #16
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Exception Handling makes GUI slow

    Quote Originally Posted by TomTom1 View Post
    @jim,
    I probably could disable the timer when an exception is thrown. But then I can't check whether there is a valid signal at a later point.
    Once the Exception is processed, I would expect you to restart the timer. This is very similar to programming interrupts (although event processing
    is more analogous). In low level system routines, usually assembler, one will process interrupts. So when the interrupt triggers, the priority of the code
    is set to high or interrupts are disabled until that particular interrupt is processed. Otherwise, the code can get interrupt bound. So as you continue to
    process interrupts, more are triggered. This can be a big contributor to poor performance.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Exception Handling
    By Bicentric in forum New To Java
    Replies: 1
    Last Post: 07-22-2012, 09:37 PM
  2. java event handling is too slow
    By yemista in forum AWT / Swing
    Replies: 4
    Last Post: 05-16-2012, 04:58 AM
  3. Exception Handling
    By link6790 in forum New To Java
    Replies: 16
    Last Post: 05-19-2011, 06:57 PM
  4. Exception Handling
    By liljester in forum New To Java
    Replies: 4
    Last Post: 06-21-2010, 03:09 PM
  5. Exception Handling...
    By focus_nitin in forum New To Java
    Replies: 1
    Last Post: 02-16-2008, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •