Search in sources :

Example 1 with ApiResponseDTO

use of com.safframework.study.task.web.dto.ApiResponseDTO in project RxJavaInAction by fengzhizi715.

the class TasksController method concurrent.

@GetMapping("/concurrent")
public ApiResponseDTO concurrent(@RequestParam("task") int[] taskDelaysInSeconds, @RequestParam("threads") int numberOfConcurrentThreads) {
    StopWatch watch = new StopWatch();
    watch.start();
    List<ITask> delayedTasks = IntStream.of(taskDelaysInSeconds).mapToObj(MockTask::new).collect(Collectors.toList());
    new ConcurrentTasksExecutor(numberOfConcurrentThreads, delayedTasks).execute();
    watch.stop();
    return new ApiResponseDTO(watch.getTotalTimeSeconds());
}
Also used : ITask(com.safframework.study.task.core.common.ITask) ConcurrentTasksExecutor(com.safframework.study.task.core.impl.ConcurrentTasksExecutor) ApiResponseDTO(com.safframework.study.task.web.dto.ApiResponseDTO) StopWatch(org.springframework.util.StopWatch)

Example 2 with ApiResponseDTO

use of com.safframework.study.task.web.dto.ApiResponseDTO in project RxJavaInAction by fengzhizi715.

the class TasksController method sequential.

@GetMapping("/sequential")
public ApiResponseDTO sequential(@RequestParam("task") int[] taskDelaysInSeconds) {
    StopWatch watch = new StopWatch();
    watch.start();
    IntStream.of(taskDelaysInSeconds).mapToObj(MockTask::new).forEach(MockTask::execute);
    watch.stop();
    return new ApiResponseDTO(watch.getTotalTimeSeconds());
}
Also used : MockTask(com.safframework.study.task.core.impl.MockTask) ApiResponseDTO(com.safframework.study.task.web.dto.ApiResponseDTO) StopWatch(org.springframework.util.StopWatch)

Aggregations

ApiResponseDTO (com.safframework.study.task.web.dto.ApiResponseDTO)2 StopWatch (org.springframework.util.StopWatch)2 ITask (com.safframework.study.task.core.common.ITask)1 ConcurrentTasksExecutor (com.safframework.study.task.core.impl.ConcurrentTasksExecutor)1 MockTask (com.safframework.study.task.core.impl.MockTask)1