In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is multithreaded FutureTask". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is multithreaded FutureTask"?
The author learns about the FutureTask wrapper today. To put it simply, the wrapper is the wrapper for the execution of the underlying thread task, including return values, exception throws, and so on. For example, we now have a task that needs to be executed by handing in a run method. At this time, we call the start method of Thread, and then JVM starts a thread to help us execute the method, but run returns a value of void and cannot throw an exception, which requires a wrapper to wrap it. Today, the author will implement the simple underlying implementation principle of FutureTask by myself.
First create the MyCallable interface, add the method of unimplemented myCall, which returns the return value of type T, and then hand it over to the custom MyFutureTask task wrapper for execution.
Write the MyFutureTask class to implement the Runnable interface, why implement this interface, because we need to give the myCall interface to the underlying thread of JVM to execute. Usually, the constructor of Thread is passed into the Runnable interface. Then call the run method of Runnable. We also need to start a thread to pass in the MyFutureTask object later. Let the underlying thread open a thread to help us execute the fun method of MyFutureTask.
MyFutureTask overrides the run method of Runnable, calls the myCall method of myCallable to perform the task, and gets the returned result. Here the underlying JVM will open a thread to help us execute the run method.
Then in the run method, if the thread task finishes executing, this modifies its state to COMPLETE and wakes up the waiting thread. Thread communication is involved here. I will simply mention that there will be a project to record later.
At this point, I believe that everyone has a deeper understanding of "what is multithreaded FutureTask", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.