Using Thread Pool for calling api without blocking main thread.
Development Environment: IntelliJ
.
Programming Language: Java
.
Using thread pool with maximumPoolSize is 2, so when calling 3 GET http requests, this program uses 2 threads (id=12,11) to call api, any threads (id=11) has completed to
get data, it continues to call the rest.
According to below image, this implement does not block main thread,
because this program can print "Do something when calling api!" before fetching data successfully.
Problem:
- Using threadPool.execute, we cannot handle the responses of apis
- After calling api, thread id 11 still waits for the results but I expect this thread will be release after calling successfully and continue to call the rest
Using InvokeAll, I can handle data after fetching but it blocks main thread...