-
-
Save bsideup/a08c4f0b10dbacde82c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.example.calculator.protocol.TOperation; | |
+import com.google.common.util.concurrent.*; | |
import org.springframework.stereotype.Component; | |
import com.example.calculator.service.CalculatorService; | |
import org.springframework.beans.factory.annotation.Autowired; | |
+import java.util.concurrent.*; | |
+ | |
@Component | |
public class CalculatorServiceHandler implements TCalculatorService { | |
@Autowired | |
CalculatorService calculatorService; | |
+ ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10); | |
+ | |
@Override | |
- public int calculate(int num1, int num2, TOperation op) throws TDivisionByZeroException { | |
+ public ListenableFuture<Integer> calculate(int num1, int num2, TOperation op) throws TDivisionByZeroException { | |
+ return JdkFutureAdapters.listenInPoolThread( | |
+ scheduledExecutorService.schedule(() -> { | |
switch(op) { | |
case ADD: | |
return calculatorService.add(num1, num2); | |
@@ -32,5 +40,7 @@ | |
default: | |
throw new IllegalArgumentException("Unknown operation " + op); | |
} | |
+ }, 2, TimeUnit.SECONDS) | |
+ ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment