I want to create a ThreadPool for a series of database calls(serial). We want to save those milliseconds. So we don’t want to waste time in executing the database queries in serial.
I’m working on a server application which already have many parallel nodes. In one of those nodes there are a series of database calls. I want to introduce parallelism inside a node that already running in parallel with other nodes.
Is thread pool executor a good choice? I don’t know how many queries I’ll be running. It depends on the state of the request object. So I can’t fix the queue size of the thread pool.
This is the example that I have found.
Is this efficient? Is there any other alternative? Any suggestions will be appreciated.
Spawning your own threads in a Java EE environment is usually a bad idea. Sometimes it has to be done, but you shouldn’t do it if there’s an alternative. I’m not sure exactly what you’re trying to do, and what version of Java EE you’re on, but if it’s 6, then maybe you could use an asynchronous EJB.