About Runnable:Runnable interface is implemented by the Thread class as well and it's a common protocol for all the objects who wish to execute in a different thread. it's one of the ways of creating threads in Java. the other way to create a thread
This article describes the callable and the future, they are very interesting, one produces results, one to get results.Callable interface is similar to runnable, can be seen from the name, but Runnable will not return results, and can not be thrown
Demo1: Gets the return value of a thread using Futuretask and callable. You can do other things before you get the return value, block at Future.get (), or callThe Get (long timeout, Timeunit unit) method sets the exception after waiting for a long
Then on a continuation of the contract and the study, this article describes the callable and future, they are very interesting, one produces results, one to get results.Callable interface is similar to runnable, can be seen from the name, but
Runnable encapsulates a task that runs asynchronously, without an asynchronous method with parameters that do not have return values. Callable and runnable are similar, but there are return values, and the callable interface is a parameterized type,
First, Thread safety classWhen a class is already well synchronized to protect its data, this class is called thread-safe. When a collection is safe, there are two threads operating on the same collection object, and when the first thread queries
If a method needs to accept a callback method as a parameter, we can write
Output:
Do STH callback
But we are not sure whether the callback method can be called, so there is a lot of extra work to be done to check whether this callback method
If a method needs to accept a callback method as a parameter, we can write
Output:
Do STH callback
But we are not sure whether the callback method can be called, so there is a lot of extra work to be done to check whether this callback method
Transferred from: http://blog.csdn.net/ghsau/article/details/7451464This article describes the callable and the future, they are very interesting, one produces results, one to get results.Callable interface is similar to runnable, can be seen from
Then on a continuation of the contract and the study, this article describes the callable and future, they are very interesting, one produces results, one to get results.Callable interface is similar to runnable, can be seen from the name, but
Before Java5, threads are not return values, often for "have" return value, a lot of trouble, and the code is very difficult to write. Or just go around the ridge and take the other way. Now Java finally has a task that can return a value (also
Public interface callable A task that returns results and may throw an exception. The implementing person defines a method called call without any parameters .public interface future The future represents the result of an asynchronous calculation.
If a method needs to accept a callback method as an argument, we can write
Output:
Do STH callback
But we are not sure if the callback method can be invoked, so a lot of extra work needs to be done to check whether this callback
Demo1: Gets the return value of a thread using Futuretask and callable. You can do something else before you get the return value, block when Future.get (), or you can call the
The Get (long timeout, Timeunit unit) method sets the exception to throw
One, the object1. The object type is divided into:A. Variable (mutable) objects include, list, dictionary (dictionary);B. Immutable (immutable) objects include, tuple (tuple), numeric value (number), string;2. Comparison of objects:A. Identity
This article mainly introduces the PHP callable forced to specify the type of callback method, very good, with reference value, the need for friends can refer to the following
If a method needs to accept a callback method as a parameter, we can
Starting with java5, many new APIs for managing scheduling threads have been introduced into the class library, most commonly the executor (actuator) Framework. Executor helps programmers manage thread objects and simplifies concurrent programming
Callable<> and runable are similar and are used for concurrent execution of Java.The only difference is that the return of the runable run method is void, and the call method of callable has a return value .The type returned by the call method 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.