0

I have written a multi threaded Java program which works just fine. However the data that it prints to the console every second, I want saved to a mySQL database.

My issue is, I can't just use one database connection because it would just bottleneck with queued statements to be executed.

There are hundreds of threads being run at one so I need something like a multi threaded mySQL connection class.

I have briefly looked at DBCP but am not sure would it be suitable or how to implement it.

I would like to know how others have overcome this quite large issue.

Thanks

EDIT: Forgot to mention that this is a Java desktop app, not Java EE

1
  • I am a total neophyte in this field and so cannot answer this question, but would connection and/or thread pooling help in any way? Such as pooling available through Apache? Commented May 8, 2015 at 0:24

1 Answer 1

1

What you want is a Connector/J connection pool, which will host some number of connections and loan them out to threads as they need it.

See here, complete with example: http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-j2ee-concepts-connection-pooling.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thank looks very interesting, it is written for Java EE in the example. I will look further into this tomorrow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.