I have a java spring boot application project. I want to implement thread parallelism there when multiple users login into that application. the response time is currently increasing. for a single user the response time is 200 millisecond. for multiple users it goes to 9 to 10 seconds. we need to reduce it. currently we have enable @EnableAsync and a TaskExecutor is also used in the application. How should i start. can anyone please help me.
currently we have tried some concurrency enable @EnableAsync and a TaskExecutor is also used in the application.
a sample controller.
@RestController
@RequestMapping("left/transfer/api26")
Class Transfer
{
private static Logger logger = LogManager.getLogger(TransferController.class);
@GetMapping("/transfer/getById/{id}")
public Response getTransferByID(HttpServletRequest request, @PathVariable("id") String id) {
auditLogger.audit("GET_ONE_TRANSFER", request.getRemoteAddr());
logger.info("Entered into getTRANSFERByID() => TRANSFER");
Response response = new Response();
Map<String, Object> transferResponse=new HashMap<String, Object>();
try {
transferResponse = transferservice.getTransferDataById(id);
if (!transferResponse.isEmpty()) {
response.setData(transferResponse);
response.setMessage("Transfer Data Fetched");
response.setStatus("Success");
} else if (transferResponse.isEmpty()) {
logger.error(transferResponse);
response.setMessage("No transfer Object Found");
response.setStatus("Failed");
}
} catch (Exception e) {
logger.error("gettransferByID() controller error ==> Issue Found " + e.getMessage() + e);
response.setData(null);
response.setMessage(e.getMessage());
response.setStatus("Failed");
}
return response;
}
}
main class
@SpringBootApplication()
@EnableAsync
@ComponentScan("com.ser.left.sectioncore398")
@Configuration
@EnableAutoConfiguration
public class SerApplicationMainclassLoader {
@Value("${CorePoolSize}")
int CorePoolSize;
@Value("${MaxPoolSize}")
int MaxPoolSize;
@Value("${QueueCapacity}")
int QueueCapacity;
private static Logger logger = LogManager.getLogger(SerApplicationMainclassLoader.class);
public static void main(String[] args) {
logger.info("Main class is getting Invoked");
SpringApplication.run(SerApplicationMainclassLoader.class, args);
}
@Bean(name = "processExecutor")
TaskExecutor workExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setThreadNamePrefix("Mains-");
threadPoolTaskExecutor.setCorePoolSize(CorePoolSize);
threadPoolTaskExecutor.setMaxPoolSize(MaxPoolSize);
threadPoolTaskExecutor.setQueueCapacity(QueueCapacity);
threadPoolTaskExecutor.afterPropertiesSet();
logger.info("ThreadPoolTaskExecutor set");
return threadPoolTaskExecutor;
}
}