Reputation: 774
I am looking for a better design pattern, or a best practice, to create a program, which has a thread spawned from main thread, and this thread ahead spawns multiple threads, and those thread spawns multiple threads ahead.
Main -> processes -> output used for a thread-level-1
thread-level-1 -> processes -> output used for a thread-level-2
thread-level-2 -> processes -> output used for a thread-level-3
Upvotes: 0
Views: 55
Reputation: 3337
From your comment it seems like you have some kind of tasks that yield other tasks, but each task can be executed individually.
Try using an ExecutorService
to submit Runnable
s or Callable
s to, depending on what suites you best. Within your tasks, you can then submit to the very same ExecutorService
, without actually creating threads.
For the actual implementation, have a look at ThreadPoolExecutor
- it will basically manage all the threading stuff for you.
Upvotes: 1