multithreading via callable interface2016-05-26 12:35 460 People read comments (0) Collection report Category: J2SE (38)
Copyright NOTICE: This article is the original article of the blogger, without the permission of the blogger may not be
Runnable is a standalone thread that performs work, but it does not return any values. If you want the thread to return a value when it is finished, you can implement the callable interface instead of the Runnable interface. The callable introduced
Implement the Callable interface. The Return Value of the callable thread.
Callable
1. A return value can be provided after the task ends.
2. The call method can throw an exception.
3. Run callable to get a Future object. The Future object indicates
I. OverviewThe interface is located under the Java.util.concurrent package, declared: Publicinterfacecallable V - Call The result type of the methodA task that returns the result and may throw an exception. The implementing person defines a method
How to implement multithreading three:A: Create a thread pool object that controls the creation of several thread objects.public static Executorservice newfixedthreadpool (int nthreads)B: Do a class to implement the callable interface.C: Call the
Threadpoolexecutor provides another very powerful interface, and that is callable. This interface is similar to runnable, but implementing thisThe method of the interface is the call method, which can return a value, making up the sorrow that
1) runnable and callable are the same interface* Callable's task can return a value after execution, and Runnable's task is not to return a value (is void); The call method can throw an exception, and the Run method cannot* Run the callable task to
Java multithreading ~~~ Callable Interface
ThreadPoolExecutor provides another very powerful interface, that is, callable. This interface is similar to runnable,
The method of the interface is the call method, which can return values, making up for
The first two blogs (multithreading-inheriting the Thread class and multithreading-implementing the Runnable interface) introduced two methods for java to use the Thread. This blog continues to introduce the third method-implementing the Callable
Callable is an interface similar to runnable, where classes that implement callable and classes that implement runnable are tasks that can be performed by other threads.Pros: There are return valuesCons: Implementing tediousSimple
----------------------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
A, process and thread
1. What is the process?
Narrowly defined: Processes are instances of running programs (an instance of the a computer program, is being executed).
Generalized definition: A process is a program with a certain number of
thread pool ConceptThe thread pool, in fact, is a container that accommodates multiple threads, where threads can be reused, eliminating the need to create thread objects frequently and consuming excessive resources without having to create threads
What is synchronization in Java? What is async? We have to be clear about these two concepts. Only by defining these two concepts can you explicitly use synchronous and asynchronous in what scenarios.Here I can figure out an example to identify
Threading OverviewThe operating system supports running multiple tasks at the same time, each of which is a program, and each running program is a process. When a program runs, the internal may contain multiple sequential execution flows, and each
I. Process: a dynamic execution of a program that corresponds to a complete process of loading from code, execution to execution, is a dynamic entity that has its own lifeCycle. It is created because it is scheduled to run, is waiting for a resource
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.