JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label FutureTask. Show all posts
Showing posts with label FutureTask. Show all posts

Java FutureTask example

8:24 AM
FutureTask class has been introduced in JDK 5 with Executor Framework. FutureTask class is the concrete implementation of the  Future  object and provides methods for start and cancel the task.It also provides method to see if the computation is done or not. We can query FutureTask object and get the result of computation. If we call get method on FutureTask object, it is blocking call and returns once the computation is done. Let’s understand more with the example. Java FutureTask example: Let’s create a very simple example. Step 1: Create a Callable task named “MultiplyingTask.java”. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23   package org . arpit . java2blog ; import java . util . concurrent . Callable ;   public class MultiplyingTask implements Callable { int a ; int b ; long sleepTime ;   public MultiplyingTask ( int a , int b , long sleepTime ) {

.