Skip to content

khoadtang/AsyncWithExecute

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Using Thread Pool for calling api without blocking main thread.
Development Environment: IntelliJ.
Programming Language: Java.

AsyncWithExecute Branch

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.

image

Problem:

  1. Using threadPool.execute, we cannot handle the responses of apis
  2. 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

AsyncWithInvokeAll Branch

Using InvokeAll, I can handle data after fetching but it blocks main thread...

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%