0

I am currently writing WebCrawler, which operates over 8 threads, each thread gets page, scrapes for links and then check if the links have already been captured. If they are new links then they are stored.

This all works, but I’ve since encountered memory problems, so I started migrating the crawler over to store the data in MySQL database.

The problem I’m having, is how I get each thread to independently interact with the database, checking for data and inserting data if required.

It currently works with one thread, but as soon as I scale the thread pool, I get connection is already open errors.

Each thread has its own connection object, created on the thread for connecting to the database. Am I ignorantly concluding that these connections can be separate?

1 Answer 1

1

Apologies, it turns out that there was actually an error in my code and I was opening the connection twice in same thread.

For reference if other people have similar problems. It is possible to connect multiple times to the same database across multiple threads from C#. As long as each connection object is thread safe and independent of the others.

I don't know if its safe or possible to share one connections over multiple threads. But as I'm up and running Its not a question or problem I need to test.

Thanks

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

Comments

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.