I made a thread like this one bellow:
public class MyThread implements Runnable {
private int temp;
public MyThread(int temp){
this.temp=temp;
}
In this case, you have to use Callable instead of Runnable (very similar): http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html
public class MyThread implements Callable {
private int temp;
public MyThread(int temp){
this.temp=temp;
}
@Override
public Integer call() {
temp+=10;
return temp;
}
}
public static void main(String[] args) throws InterruptedException, ExecutionException {
ExecutorService service = Executors.newSingleThreadExecutor();
MyThread myTask = new MyThread(10);
Future future = service.submit(myTask);
Integer result = future.get();
System.out.println(result);
}