In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how SwingWorker enhances exception handling. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The new SwingWorker supports timeouts by overriding that the getTimeout () method has returned a non-zero value. When the timeout is exceeded, the worker thread is interrupted.
If you want to see examples of using timeouts, see the annotated version of the getTimeout () method and how DynamicTree handles TimeoutException.
The timeout function is implemented in TimedCallable, where the timedGet () method of FutureResult is used.
Enhanced exception handling
Anything thrown by the construct () method is recorded. In addition to deadloops and deadlocks, the new exception handling ensures that SwingWorker is in a "ready" state. That is, it either gets a correct result or an exception.
The following get () method is used to fetch the result. This method inherits from FutureResult:
◆ publicObjectget ()
◆ throwsInvocationTargetException,InterruptedException
If construct () throws an Exception,get () method, it throws InvocationTargetException. To get the exception actually thrown by the construct () method, you can call getTargetException () for exception handling.
The get () method throws an InterruptedException-- if the thread fetching the result is interrupted while waiting for the result, but this is rare for SwingWorker because the thread taking the result is usually an event dispatch thread, and the result is always ready before finished () is called.
More invocation tools
The implementation of SwingWorker is in the jozart.swingutils package. You can also find the InvokeUtils class in the same package, which also provides several invokeXXX () methods. The background thread can use these methods to get values and user input in the event dispatch thread, and then return the results to the background thread.
Thank you for reading! This is the end of the article on "how to enhance exception handling in SwingWorker". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.