Home » Language IDEs » Java Development Tools (JDT) » File locking error while using Ant(FileHandler can't get lock from Ant in Galileo)
File locking error while using Ant [message #515313] |
Thu, 18 February 2010 08:21  |
Eclipse User |
|
|
|
I have a Java project that runs just fine in Eclipse 3.5.1 using the "Run as Java application" option. However, when I execute the same program via an Ant script, I get a java.io.IOException. The error message says "Couldn't get lock for log\mylog.xml".
Looking at the Java code, the problem exists in FileHandler.class, specifically in this constructor:
public FileHandler(String pattern, int limit, int count, boolean append)
This is the code that is crashing:
int unique = -1;
for (;;) {
unique++;
if (unique > MAX_LOCKS) {
throw new IOException("Couldn't get lock for " + pattern);
}
It appears that I am exceeding MAX_LOCKS but I'm not sure what value MAX_LOCKS has, why I'd be exceeding that value, or how to prevent it from exceeding it.
Any idea why I'd get this behaviour in Ant but not when I run the program with the "Run as Java application" option?
For what it's worth, I ran this program successfully via Ant many times in previous versions of Eclipse, like 3.1. Also, I tried rebooting the computer and deleting all of the existing log and lck files in the log directory before trying the program again but it still behaves the same way: it messes up in Ant but runs fine when executed as a Java application outside of Ant.
Have I found a bug in Eclipse 3.5.1, specifically in the Ant code? If yes, what should I do about it? File a Bugzilla report? Upgrade Ant or Eclipse to a newer (or older?) version?
I am running on Windows XP.
--
Rhino
|
|
| | |
Re: File locking error while using Ant [message #515339 is a reply to message #515313] |
Thu, 18 February 2010 04:22   |
Eclipse User |
|
|
|
Hi,
This reminds me of a problem I had quite some time back. I thought I had
posted a bug report at the time, but couldn't now seem to find it. IIRC,
what happened to me, then, was the following:
I had an ANT script that opened files and did something to them. Closing
the files was implicit upon the end of ANT respectively the end of the
particular Java program triggered from ANT. The same file could be
opened multiple times in one run of the same ANT script. This worked
fine when using ANT from command line, but failed to work when using ANT
from within Eclipse. The reason was that when using ANT from within
Eclipse, the implicit close doesn't happen until Eclipse terminates
(because as far as the VM and the OS are concerned this is the only
process that there is). That wouldn't necessarily be a problem, but
under Windows opened files automatically get a lock that is also
associated with the process, so they cannot be reopened. I cannot quite
remember what the fix was, if there was one, but I assume I must
eventually have figured out a way to make the file close explicit within
my work flow.
hth,
Steffen
On 18/02/2010 13:21, Reinhardt Christiansen wrote:
> I have a Java project that runs just fine in Eclipse 3.5.1 using the
> "Run as Java application" option. However, when I execute the same
> program via an Ant script, I get a java.io.IOException. The error
> message says "Couldn't get lock for log\mylog.xml".
> Looking at the Java code, the problem exists in FileHandler.class,
> specifically in this constructor:
>
> public FileHandler(String pattern, int limit, int count, boolean append)
>
> This is the code that is crashing:
>
> int unique = -1;
>
> for (;;) {
>
> unique++;
>
> if (unique > MAX_LOCKS) {
>
> throw new IOException("Couldn't get lock for " + pattern);
>
> }
>
> It appears that I am exceeding MAX_LOCKS but I'm not sure what value
> MAX_LOCKS has, why I'd be exceeding that value, or how to prevent it
> from exceeding it.
>
> Any idea why I'd get this behaviour in Ant but not when I run the
> program with the "Run as Java application" option?
>
> For what it's worth, I ran this program successfully via Ant many
> times in previous versions of Eclipse, like 3.1. Also, I tried
> rebooting the computer and deleting all of the existing log and lck
> files in the log directory before trying the program again but it
> still behaves the same way: it messes up in Ant but runs fine when
> executed as a Java application outside of Ant.
> Have I found a bug in Eclipse 3.5.1, specifically in the Ant code? If
> yes, what should I do about it? File a Bugzilla report? Upgrade Ant or
> Eclipse to a newer (or older?) version?
>
> I am running on Windows XP.
> --
> Rhino
|
|
| |
Re: File locking error while using Ant [message #515479 is a reply to message #515338] |
Thu, 18 February 2010 16:23   |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
The code indicates:
1) It will look for lockfiles ( lockFileName = generate(pattern, 0,
unique).toString() + ".lck"; ) whatever the lock file name pattern is
generated, it will try for up to 100 of these files and if they all
exist in the file system then you will get this error.
or
2) It has a static map of lock files, and if the request file, even if
not in the file system IS in this static then it will increment unique
and try again.
or
3) It tries to open for output this file, and if it can't then it will
increment unique and try again
or
4) It tries to actually lock the file, and if it can't then it will
increment unique and try again
------------------
So this means that some files are being locked and then never released
that use the given "pattern" for locking. They are released by having
the associated filehandler closed.
You didn't say if you are running this from Eclipse as an Ant launcher
or from a command line.
If you are running from a command line this means you are doing many
locks and no unlocking.
If you are running from Eclipse AND you are having run WITHIN Eclipse
instead of a separate JRE then it will be using the same JRE instance as
Eclipse is using and so if you don't unlock, even though the Ant script
has terminated, the file will stay locked because it is a static inside
the Eclipse JVM instance. So every time you run the Ant script the
number of locks would increase.
--
Thanks,
Rich Kulp
|
|
|
Re: File locking error while using Ant [message #515490 is a reply to message #515479] |
Thu, 18 February 2010 18:56   |
Eclipse User |
|
|
|
Thank you for that information, Rich.
I'm not sure if I entirely understand what you are saying. As a result of your words, I've rebooted the computer and deleted all existing log files - there were only 3, nowhere near to 100 - on the theory that a reboot would surely unlock any locked files. (Perhaps this is not correct?). I also changed the JRE in the Ant configuration settings to be a different one that my default in Eclipse. Now, Eclipse is using a default of 1.6.0_18 while Ant is using a 1.6.0_07 JRE. When I ran the Ant script again, I got the exact same error as before.
In answer to your question, I am running Ant from within Eclipse and NOT from the command line.
If I have indeed exceeded the number of locks I am allowed to have and rebooting doesn't clear those locks, what is the right way to close them?
Also, is there any way I can programmatically determine what locks exist, inspect them, and then close the ones that I want to close? Or is there some feature of Eclipse that will help me do this? I'm not sure what a 'static' is in this context and I certainly know very little about how Eclipse works internally, especially with regards to opening/closing files and locking/unlocking them.
Should my programs make a point of always manually unlocking files? If so, how do I do that? I had assumed that locking and unlocking was handled by Java or the OS and that I didn't need to bother with it so I'm not sure how to go about it.
If you can clarify these points for me, I think we'll be on the way to a solution....
--
Rhino
|
|
| | | | | | |
Re: File locking error while using Ant [message #515651 is a reply to message #515629] |
Fri, 19 February 2010 11:09  |
Eclipse User |
|
|
|
I only execute the compile task once in the Ant script.
The main program instantiates a variety of classes and each of the classes that needs it, creates a log fle. In fact, the exact same physical file, i.e. a file having the exact same file name and stored in the same directory, is being created each time. I realize that is redundant but it never occurred to me until I started working through this problem with you since I'd never had a problem before running this program in Ant on my new Eclipse version.
However, despite that dubious design - I'm sure it would make more sense to create a single instance of the log file at the beginning and then simply share it with each class that needs it - the fact remains that I don't get this problem when I run the program as a Java application. Also, I get the lock error the very first time the class tries to open the log file but ONLY when I run the program via Ant, never when I run it as a Java application.
I'm putting together a bare-bones self-contained standalone example that illustrates the problem and it is experiencing the same problem. Would it be helpful to post this? That would enable others to try this and see if they get the same results.
--
Rhino
|
|
|
Goto Forum:
Current Time: Wed Mar 26 01:36:34 EDT 2025
Powered by FUDForum. Page generated in 0.04439 seconds
|