Solved

Lucene: "FileNotFoundException"

Posted on 2004-04-30
9
296 Views
Last Modified: 2012-08-13
I'm using threads in which i'm searching an xml index and sometimes updating the index also.....

However, (probabaly on the occasions when the two threads(+) conincide) i get a "FileNotFoundException": the system cannot find the path specified...
or else an "IOException": couldn't delete _4.fl

So, i'm presuming that there is a conflict, whenever there may be an indexing and a search at the same time?

(By the way.....
I'm using Digester to parse & index the xml file
In my xmlParser class, i have a 'contacts' class (which holds all the properties or each contact entry which must be declared public and static for digester to instantiate it....)

How could i make sure these two errors never occur.......
0
Comment
Question by:vinoboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 10958628
>> couldn't delete _4.fl

Do you also try to delete the files somewhere?
0
 

Author Comment

by:vinoboy
ID: 10958743
No, i didn't, but i presume that when its updating the index (ie, overwriting i think) that it deletes them itself
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10958771
Make sure that you synchronize your file-access properly. Ideally, when a file is being read by a thread, no other thread should write to it till that one closes it. Sameway, if a file is being written into by one thread, you should not let any other thread read from it till this one closes it.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vinoboy
ID: 10958800
And an easily implementable and reliable way to do the synchronisation of file access is?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10958839
Perhaps you could use a common log-file. If a file is being written to, then the program would write its name to this file. Any other threads trying to access that file would wait till the file's entry is removed from that log-file (which will be done by the thread using it, after it is done with the file).

You could also carefully use synchronization between threads, but I don't have your code to help you with that.
0
 

Author Comment

by:vinoboy
ID: 10958887
I'll give the log file a shot....Its mere existance could tell me that the 'updating index' program is been used...
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10958918
Don't check only for existance. Let the log-file always be there. Let the existance of the working file-name in the log-file decide whether it is to be accessed or not. You can write a separate class for this log-file purpose.
0
 
LVL 4

Expert Comment

by:illusionz70
ID: 10959066
use locks to lock the file before you access it so that no other thread/process can change it

import java.nio.channels.*; //works on 1.4 only

FileLock lck = new FileOutputStream("C:\\File").getChannel().tryLock();
            if(lck == null)
                               {
      System.out.println("Another thread is already accesing the file....");
            }

c:\\file can be the common file which is locked.if this file is not locked then a thread can do the required if it is locked then the thread has to wait.

cheers
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 100 total points
ID: 10959155
Ah, indeed~! Should've thought of that! Have been working on 1.3 a lot these days! You can see more on locks here:

http://www.javaalmanac.com/egs/java.nio/SetFileLock.html

http://www.javaalmanac.com/egs/java.nio/SharedLock.html
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
throw exception 21 76
ejb message driven bean mdb creation steps 2 52
Bot application - advice 3 79
Setup GlassFish 4 55
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

737 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