why java connection cannot createstatement() while an executeQuery() is in the middle of processing ?

StackOverflow https://stackoverflow.com/questions/15683770

  •  30-03-2022
  •  | 
  •  

Question

I have a static java connection to a databases.

1st Thread

with my static connection I am creating a statement and call to executeQuery() method. at this point I'm waiting because the query results is very big and I have to wait more than 15 minutes.

2nd Thread

with the same static connection I am trying to make a call to createStatement() method. And here the 2nd thread is blocked.

There are many ways to solve this issue, but I don't find anywhere why this aproach should not working. Any ideas?

Was it helpful?

Solution

In a common way, the single Connection to the database is implemented through Sockets mechanism. Better to say, that your single connection is some kind of pipe, which is using for concrete query which is executing one per time.

It is hard to imagine such optimal and high-perfomance code implementation, where though one socket multiple queries and their results are sent in parallel. Such implementation could cause the confusion with data-packets and at least their lost.

As karmanaut mentioned above in comments, you need to implement DB pool, i.e. pool of connections, which will be used for each statement concurrently.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top