• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple threads to be created and require use of database access  RSS feed

Vaibhav Jaiswal
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a newbie to spring and having trouble in implementing a requirement. Let me explain my requirement.
We have a hierarchial architecture where there is a parent server that controls access to downstream m/c.
The server is supposed to periodically collect the data from the downstream machines and store it in the database. So an approach is to spawn multiple threads (kind of executor interface) to collect the data and store the data in the database. Where we can fine tune the number of thread as per the load on the system.
Now the server is running the spring software and the multiple threads need access to the database.
How shall I do it in spring?
As far as I understood it is not recommended to use multiple threads and better to use TaskExecutor. The task has to be created dynamically and will probably be run on a separate thread. How shall this dynamically created task gain access to DAO(basically entity manager). If I pass a reference injected into my task creation bean can that be then passed as an argument to constructor, remember the bean may go out of scope after this.
These are some of the questions I am struggling with. Please tell me what would be the best way to implement such a requirement.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!