Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Error from java.nio.channels.FileChannel.tryLock()

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Michael.Giroux@bull.com

Error from java.nio.channels.FileChannel.tryLock()

#1 Post by Michael.Giroux@bull.com »

A customer using debian Linux is getting an exception from
java.nio.channels.FileChannel.tryLock() method.

java.nio.channels.FileChannel channel = new RandomAccessFile(file,
fileMode).getChannel();
java.ino.channels.FileLock lock = channel.tryLock();

> org.objectweb.howl.log.LogConfigurationException: java.io.IOException:
> Value too large for defined data type
> at org.objectweb.howl.log.LogFile.open(LogFile.java:179)

Java docs for tryLock() say this is equivalent to tryLock(0L,
Long.MAX_LONG,false); which is a request to lock the entire file.

This code works on various Windows, Linux, and MacOS systems. I do not have
access to a debian system, so I wonder if someone could kindly throw
together a small java app to test this for me on debian?

The customer is using JVM 1.5, so I suspect it is either Sun or Jrockit, but
the customer has not told me which.

Thanks
Michael Giroux
import java.io.*;
import java.nio.channels.*;
public class test {
public static void main(String[] args) {
try {
java.nio.channels.FileChannel channel = new RandomAccessFile("test.txt", "rw").getChannel();
java.nio.channels.FileLock lock = channel.tryLock();
System.out.println("Success");
} catch (IOException e) {
e.printStackTrace();
}
}
}

Scotti
Moderator Team Member
Moderator Team Member
Posts: 305
Joined: 2005-11-08 01:13

#2 Post by Scotti »

Code: Select all

scotti@quadmg:~$ javac test.java 
scotti@quadmg:~$ java test
Success
scotti@quadmg:~
Worked for me.

Code: Select all

scotti@quadmg:~$ java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)
scotti@quadmg:~$

waiyung

java error

#3 Post by waiyung »

Would someone happens to have a java and kernal version same as I try out the following code? I would like to know is it kernal related.

-----------------------
waiyung:~/workspace/myproject/src# cat test.java
import java.io.*;
import java.nio.channels.*;
public class test {
public static void main(String[] args) {
//FileLock fl = null;
try {
FileOutputStream fos = new FileOutputStream("testFile2.tmp");
FileChannel ch = fos.getChannel();
FileLock fl = ch.lock();
//FileLock fl = ch.lock(0L,20*1024*1024,false);//.lock();
fos.write(new byte[128]);
System.out.println(Long.MAX_VALUE);

} catch (IOException e) {
System.out.println("Unexpected exception: "+e);
e.printStackTrace();
System.exit(0);
}
System.out.println("PASSED.");
}
}
waiyung:~/workspace/myproject/src# java test
Unexpected exception: java.io.IOException: Value too large for defined data typejava.io.IOException: Value too large for defined data type
at sun.nio.ch.FileChannelImpl.lock0(Native Method)
at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:784)
at java.nio.channels.FileChannel.lock(FileChannel.java:865)
at test.main(test.java:9)
waiyung:~/workspace/myproject/src# java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
waiyung:~/workspace/myproject/src# uname -a
Linux waiyung 2.2.20-idepci #1 Sat Apr 20 12:45:19 EST 2002 i686 GNU/Linux

waiyung

lock error

#4 Post by waiyung »

I upgraded my kernel and the bug is fixed.

-----------------------------------------

waiyung:~/workspace/myproject/src# java test
9223372036854775807
PASSED.
waiyung:~/workspace/myproject/src# uname -a
Linux waiyung 2.4.27-2-k7 #1 Wed Nov 30 22:12:04 JST 2005 i686 GNU/Linux
waiyung:~/workspace/myproject/src#

Scotti
Moderator Team Member
Moderator Team Member
Posts: 305
Joined: 2005-11-08 01:13

#5 Post by Scotti »

Wow you were running 2.2? Good thing you upgraded. You might want to consider a 2.6 kernel sometime. They're pretty good. ;)

Post Reply