开发者

Multiple Execution Paths with limited Threads

开发者 https://www.devze.com 2023-03-31 18:34 出处:网络
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:

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 some开发者_C百科what 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


Use classes form java.util.concurrent, for the starters, e.g. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消