Solved Multi-threading problem.

Posted on 2005-04-19
Last Modified: 2008-03-10
Hi everyone!

I have built a web spider that is using Lucene to index the information.

However, when I implemented multi-threading, several threads are trying to write into the index at the same time, this generates an exception.

I assume the same happens with other cases, such as opening a file for writing with a thread, and then trying to access the file with another thread.

Could somebody provide some tips (code preferably) to avoid this thread conflicts or make the threads "wait" until the others have finished their job?

Thanks a lot!
Question by:glopezz
    1 Comment
    LVL 3

    Accepted Solution

    Multithreading is a very deep topic. If you're using .NET collections, the framework can do a lot of work for you. Learn about the 'lock' keyword and the .Syncronized and .SyncRoot methods of most .NET collection classes:

    All these have code examples:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    A short article about problems I had with the new location API and permissions in Marshmallow
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now