简体   繁体   中英

Multiple Execution Paths with limited Threads

I have a challenging asynchronous programming task, wonder if anyone did anything like that with Java. Let's assume I'm developing a framework which will be used like this:

  1. Do some custom Java stuff
  2. Call Framework Method
  3. Do some custom Java stuff
  4. Call Framework Method

The above code is Synchronous from the user perspective. However the Framework Methods internally perform some long asynchronous operation and blocking the User thread for the duration of the operation is not efficient/feasible. Blocking the User thread is not feasible since I might need to support thousands of concurrent executions of steps 1-4... In other words I'm looking for a way to support X concurrent Java code executions using Y threads where X > Y... It's somewhat similar to what a Reactor pattern is doing with IO, but more generic.. Any thoughts?

the normal thread pools/executors will help you with that

if you can split up the framework jobs in several atomic tasks that will activate other tasks; the jobs will be able to execute with less active threads than there are jobs to run with decent throughput

对于初学者,请使用java.util.concurrent形式的类,例如Executors

Starting with JDK 1.5 you have the Concurrency API at hand. The High Level Concurrency Objects within The Java Tutorial give you a good start at it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM