BAEL-1071 Runnable vs Callable in Java (#2513)

This commit is contained in:
baljeet20
2017-08-29 01:01:31 +05:30
committed by Grzegorz Piwowarek
parent 73526dd0a8
commit 904a740643
2 changed files with 78 additions and 0 deletions
@@ -0,0 +1,30 @@
package com.baeldung.concurrent.callable;
import java.util.concurrent.Callable;
public class FactorialTask implements Callable<Integer> {
int number;
public FactorialTask(int number) {
this.number = number;
}
public Integer call() throws InvalidParamaterException {
int fact=1;
if(number < 0)
throw new InvalidParamaterException("Number must be positive");
for(int count=number;count>1;count--){
fact=fact * count;
}
return fact;
}
private class InvalidParamaterException extends Exception {
public InvalidParamaterException(String message) {
super(message);
}
}
}