Java has several thread-related classes or interfaces, such as Runnable, Callable, Future, and FutureTask. They are also important concepts in Java, let's take a simple example below to learn the differences between them.Runnable
Among them,
Callable and future
The callable interface defines a call method that can act as the executing body of a thread, but the call method is more powerful than the Run method:
A, call method can have return valueB, the call method can declare an
The reason for the emergence of callable and futureThere are 2 ways to create threads, one is to inherit the thread directly, and the other is to implement the Runnable interface.One drawback to all 2 of these approaches is that you cannot get the
OverviewThis chapter describes the callable and future in thread pooling.Introduction to Callable and futureSample and source analysis (based on jdk1.7.0_40)Reprint Please specify source:
The reason for the emergence of callable and futureThere are 2 ways to create threads, one is to inherit the thread directly, and the other is to implement the Runnable interface.One drawback to all 2 of these approaches is that you cannot get the
First, callable and RunnableLet's talk about Java.lang.Runnable, it's an interface that only declares a run () method in it: Public Interface Runnable { publicabstractvoid run ();}Because the run () method returns a value of type void, No
----------------------Android Training, Java training, and look forward to communicating with you. ----------------------
About multithreading callable and futureImplementing multithreading we can inherit the thread class or implement the Runnable
Introduction of callable and future
callable and The future two feature is Java in subsequent versions in order to adapt to multi-method to join, callable is similar to runnable interface, Classes that implement callable interfaces and
in the previous article we talked about the 2 ways to create threads, one is to inherit the thread directly, and the other is to implement the Runnable interface. One drawback to all 2 of these approaches is that you cannot get the results of the
English documents:callable(object)Return True If the object argument appears callable, False if not. If this returns true, it's still possible that a call fails and if it is false, calling object would never Succe Ed. Note That classes is callable
Java concurrent Programming callable, Runnable, future, Futuretask Java has callable, Runnable, future, futuretask these thread-related classes or interfaces, below to understand their role and differences.I. Callable and runnable Similar to
Since Java 5, Java provides the callable interface. The callable interface provides a call method that can be used as the thread's execution body, but the call method is more powerful than the run method. Mainly reflected in:
1. The call method can
Callable, Future, and FutureTask
In Java, besides the Runnable interface, there are also Callable interfaces.The difference between the two is that the latter can return values, which are generally used for time-consuming computing.The Runnable
Callable and futureThe Executor framework divides the unit of work into tasks, that is, the task is a logical unit of work, and the thread is the mechanism by which the task executes asynchronously. Runnable is an abstraction of the task, and the
http://blog.csdn.net/pipisorry/article/details/44341579IntroductionThe callable interface represents a section of code that can invoke and return results;The future interface represents an asynchronous task. Is the future outcome of the task that
Reprint: Http://www.jianshu.com/p/cf12d4244171RunnablePublic interface Runnable {public abstract void run (); Runnable's code is very simple, it is an interface and there is only one run (), creating a class to implement it, putting some
Java Multithreading Series--"Juc thread pool" 06 of the callable and futureIntroduction to Callable and futureCallable and future are more interesting pairs of combinations. When we need to get the execution results of threads, we need to use them.
1.RunnableRunnable is an interface that is very simple to use: 1. Implement the interface and override the Run Method 2. Create thread 3 with objects of this class. The Run method that automatically calls the object when the thread starts is
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.