In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "FutureTask case Analysis of java exception programming". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "FutureTask case Analysis of java exception programming" can help you solve the problem.
Description
1. The FutureTask class implements not only the Future interface but also the Runnable interface, which represents a Runnable that can generate results.
2. FutureTask class implements the method of opening and canceling tasks of Future interface, querying whether tasks are completed, and obtaining calculation results.
To get the result of a FutureTask task, we can only get it by calling the getXXX () series of methods, which will be blocked before the result comes out. At the same time, the task can be of type Callable (with returned results) or Runnable (with no returned results).
Example
Private static void testFutureTask () throws ExecutionException, InterruptedException {System.out.println ("- testFutureTask -"); / / create a FutureTask (doOneThing task) FutureTask futureTask = new FutureTask (FutureTaskDemo::doOneThing); / / execute doOneThing task ForkJoinPool.commonPool () .execute (futureTask) using thread pool / / execute doOtherThing task String doOtherThingResult = doOtherThing (); / / synchronously wait for thread to execute doOneThing task end String doOneThingResult = futureTask.get (); / / output System.out.println of task execution result ("doOneThingResult->" + doOneThingResult); System.out.println ("doOtherThingResult-- >" + doOtherThingResult) } this is the end of the introduction to "FutureTask instance Analysis of java exception programming". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.