You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Anton Luht (JIRA)" <ji...@apache.org> on 2006/03/24 14:43:21 UTC
[jira] Created: (HARMONY-246)
java.nio.channels.FileChannel.tryLock() should be non-blocking
java.nio.channels.FileChannel.tryLock() should be non-blocking
--------------------------------------------------------------
Key: HARMONY-246
URL: http://issues.apache.org/jira/browse/HARMONY-246
Project: Harmony
Type: Bug
Components: Classlib
Environment: Windows, Linux
Reporter: Anton Luht
j2se 1.4.2 spec for java.nio.channels.FileChannel says:
tryLock(..)
Attempts to acquire a lock on the given region of this channel's file.
This method does not block. An invocation of this always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown.
in Harmony code this method blocks
Suggested fix (naive): always use O_NONBLOCK in fcntl
Code to reproduce:
import java.io.*;
public class Test {
public static void main(String args[]) throws Exception {
File f = new File("abcd");
f.deleteOnExit();
new FileOutputStream(f, true).getChannel().tryLock();
System.err.println("locked OK");
String javaCmd = System.getProperty("java.home") +
File.separator +
"bin" +
File.separator +
"java";
if(args.length == 0) {
Process p = Runtime.getRuntime().exec(new String[] { javaCmd,
"-cp",
System.getProperty("java.class.path"),
"Test", "foo" } );
String line;
InputStream is = p.getInputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(p
.getErrorStream()));
while ((line = input.readLine()) != null) {
System.err.println("Child prints: " + line);
}
input.close();
}
}
}
Steps to reproduce:
1. Build Harmony j2se subset as described in README.txt.
2. Compile Test.java using BEA 1.4 javac
> javac Test.java
3. Run java using compatible VM (J9)
> java Test
Output :
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32,
Native Threads, GC strategy: parallel)
locked OK
Child prints: locked OK
Output in Harmony:
locked OK
<here test hangs>
JUnit test:
---------------FileLockTest.java------------
import java.io.*;
import junit.framework.*;
public class FileLockTest extends TestCase {
static boolean childVM = false;
public static void main(String[] args) {
childVM = args.length > 0;
junit.textui.TestRunner.run(FileLockTest.class);
}
public void testFileLock() throws Exception {
File f = new File("abcd");
f.deleteOnExit();
new FileOutputStream(f, true).getChannel().tryLock();
System.err.println("locked OK");
String javaCmd = System.getProperty("java.home") + File.separator
+ "bin" + File.separator + "java";
if (!childVM) {
Process p = Runtime.getRuntime().exec(
new String[] { javaCmd, "-cp",
System.getProperty("java.class.path"),
this.getClass().getName(), "foo" });
String line;
BufferedReader input = new BufferedReader(new InputStreamReader(p
.getErrorStream()));
while ((line = input.readLine()) != null) {
System.err.println("Child prints: " + line);
}
input.close();
}
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Updated: (HARMONY-246)
java.nio.channels.FileChannel.tryLock() should be non-blocking
Posted by "Vladimir Strigun (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/jira/browse/HARMONY-246?page=all ]
Vladimir Strigun updated HARMONY-246:
-------------------------------------
Attachment: Harmony-246.txt
Please try my fix. I't very simple, we need just correctly pass "wait" parameter to FileChannelImpl.
> java.nio.channels.FileChannel.tryLock() should be non-blocking
> --------------------------------------------------------------
>
> Key: HARMONY-246
> URL: http://issues.apache.org/jira/browse/HARMONY-246
> Project: Harmony
> Type: Bug
> Components: Classlib
> Environment: Windows, Linux
> Reporter: Anton Luht
> Attachments: Harmony-246.txt
>
> j2se 1.4.2 spec for java.nio.channels.FileChannel says:
> tryLock(..)
> Attempts to acquire a lock on the given region of this channel's file.
> This method does not block. An invocation of this always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown.
> in Harmony code this method blocks
> Suggested fix (naive): always use O_NONBLOCK in fcntl
> Code to reproduce:
> import java.io.*;
> public class Test {
> public static void main(String args[]) throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
>
> new FileOutputStream(f, true).getChannel().tryLock();
>
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") +
> File.separator +
> "bin" +
> File.separator +
> "java";
> if(args.length == 0) {
> Process p = Runtime.getRuntime().exec(new String[] { javaCmd,
> "-cp",
> System.getProperty("java.class.path"),
> "Test", "foo" } );
>
> String line;
> InputStream is = p.getInputStream();
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
> Steps to reproduce:
> 1. Build Harmony j2se subset as described in README.txt.
> 2. Compile Test.java using BEA 1.4 javac
> > javac Test.java
> 3. Run java using compatible VM (J9)
> > java Test
> Output :
> java version "1.4.2_04"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32,
> Native Threads, GC strategy: parallel)
> locked OK
> Child prints: locked OK
> Output in Harmony:
> locked OK
> <here test hangs>
> JUnit test:
> ---------------FileLockTest.java------------
> import java.io.*;
> import junit.framework.*;
> public class FileLockTest extends TestCase {
> static boolean childVM = false;
> public static void main(String[] args) {
> childVM = args.length > 0;
> junit.textui.TestRunner.run(FileLockTest.class);
> }
> public void testFileLock() throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
> new FileOutputStream(f, true).getChannel().tryLock();
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") + File.separator
> + "bin" + File.separator + "java";
> if (!childVM) {
> Process p = Runtime.getRuntime().exec(
> new String[] { javaCmd, "-cp",
> System.getProperty("java.class.path"),
> this.getClass().getName(), "foo" });
> String line;
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Assigned: (HARMONY-246)
java.nio.channels.FileChannel.tryLock() should be non-blocking
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/jira/browse/HARMONY-246?page=all ]
Tim Ellison reassigned HARMONY-246:
-----------------------------------
Assign To: Tim Ellison
> java.nio.channels.FileChannel.tryLock() should be non-blocking
> --------------------------------------------------------------
>
> Key: HARMONY-246
> URL: http://issues.apache.org/jira/browse/HARMONY-246
> Project: Harmony
> Type: Bug
> Components: Classlib
> Environment: Windows, Linux
> Reporter: Anton Luht
> Assignee: Tim Ellison
> Attachments: Harmony-246.txt
>
> j2se 1.4.2 spec for java.nio.channels.FileChannel says:
> tryLock(..)
> Attempts to acquire a lock on the given region of this channel's file.
> This method does not block. An invocation of this always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown.
> in Harmony code this method blocks
> Suggested fix (naive): always use O_NONBLOCK in fcntl
> Code to reproduce:
> import java.io.*;
> public class Test {
> public static void main(String args[]) throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
>
> new FileOutputStream(f, true).getChannel().tryLock();
>
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") +
> File.separator +
> "bin" +
> File.separator +
> "java";
> if(args.length == 0) {
> Process p = Runtime.getRuntime().exec(new String[] { javaCmd,
> "-cp",
> System.getProperty("java.class.path"),
> "Test", "foo" } );
>
> String line;
> InputStream is = p.getInputStream();
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
> Steps to reproduce:
> 1. Build Harmony j2se subset as described in README.txt.
> 2. Compile Test.java using BEA 1.4 javac
> > javac Test.java
> 3. Run java using compatible VM (J9)
> > java Test
> Output :
> java version "1.4.2_04"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32,
> Native Threads, GC strategy: parallel)
> locked OK
> Child prints: locked OK
> Output in Harmony:
> locked OK
> <here test hangs>
> JUnit test:
> ---------------FileLockTest.java------------
> import java.io.*;
> import junit.framework.*;
> public class FileLockTest extends TestCase {
> static boolean childVM = false;
> public static void main(String[] args) {
> childVM = args.length > 0;
> junit.textui.TestRunner.run(FileLockTest.class);
> }
> public void testFileLock() throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
> new FileOutputStream(f, true).getChannel().tryLock();
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") + File.separator
> + "bin" + File.separator + "java";
> if (!childVM) {
> Process p = Runtime.getRuntime().exec(
> new String[] { javaCmd, "-cp",
> System.getProperty("java.class.path"),
> this.getClass().getName(), "foo" });
> String line;
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Resolved: (HARMONY-246)
java.nio.channels.FileChannel.tryLock() should be non-blocking
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/jira/browse/HARMONY-246?page=all ]
Tim Ellison resolved HARMONY-246:
---------------------------------
Resolution: Fixed
Anton
Fixed in NIO module at repo revision 396908.
Please check that this fully resolves your problem.
> java.nio.channels.FileChannel.tryLock() should be non-blocking
> --------------------------------------------------------------
>
> Key: HARMONY-246
> URL: http://issues.apache.org/jira/browse/HARMONY-246
> Project: Harmony
> Type: Bug
> Components: Classlib
> Environment: Windows, Linux
> Reporter: Anton Luht
> Assignee: Tim Ellison
> Attachments: Harmony-246.txt
>
> j2se 1.4.2 spec for java.nio.channels.FileChannel says:
> tryLock(..)
> Attempts to acquire a lock on the given region of this channel's file.
> This method does not block. An invocation of this always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown.
> in Harmony code this method blocks
> Suggested fix (naive): always use O_NONBLOCK in fcntl
> Code to reproduce:
> import java.io.*;
> public class Test {
> public static void main(String args[]) throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
>
> new FileOutputStream(f, true).getChannel().tryLock();
>
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") +
> File.separator +
> "bin" +
> File.separator +
> "java";
> if(args.length == 0) {
> Process p = Runtime.getRuntime().exec(new String[] { javaCmd,
> "-cp",
> System.getProperty("java.class.path"),
> "Test", "foo" } );
>
> String line;
> InputStream is = p.getInputStream();
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
> Steps to reproduce:
> 1. Build Harmony j2se subset as described in README.txt.
> 2. Compile Test.java using BEA 1.4 javac
> > javac Test.java
> 3. Run java using compatible VM (J9)
> > java Test
> Output :
> java version "1.4.2_04"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32,
> Native Threads, GC strategy: parallel)
> locked OK
> Child prints: locked OK
> Output in Harmony:
> locked OK
> <here test hangs>
> JUnit test:
> ---------------FileLockTest.java------------
> import java.io.*;
> import junit.framework.*;
> public class FileLockTest extends TestCase {
> static boolean childVM = false;
> public static void main(String[] args) {
> childVM = args.length > 0;
> junit.textui.TestRunner.run(FileLockTest.class);
> }
> public void testFileLock() throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
> new FileOutputStream(f, true).getChannel().tryLock();
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") + File.separator
> + "bin" + File.separator + "java";
> if (!childVM) {
> Process p = Runtime.getRuntime().exec(
> new String[] { javaCmd, "-cp",
> System.getProperty("java.class.path"),
> this.getClass().getName(), "foo" });
> String line;
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Commented: (HARMONY-246)
java.nio.channels.FileChannel.tryLock() should be non-blocking
Posted by "Anton Luht (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/jira/browse/HARMONY-246?page=comments#action_12372083 ]
Anton Luht commented on HARMONY-246:
------------------------------------
Vladimir, thanks for the patch - it resolves the problem.
> java.nio.channels.FileChannel.tryLock() should be non-blocking
> --------------------------------------------------------------
>
> Key: HARMONY-246
> URL: http://issues.apache.org/jira/browse/HARMONY-246
> Project: Harmony
> Type: Bug
> Components: Classlib
> Environment: Windows, Linux
> Reporter: Anton Luht
> Attachments: Harmony-246.txt
>
> j2se 1.4.2 spec for java.nio.channels.FileChannel says:
> tryLock(..)
> Attempts to acquire a lock on the given region of this channel's file.
> This method does not block. An invocation of this always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown.
> in Harmony code this method blocks
> Suggested fix (naive): always use O_NONBLOCK in fcntl
> Code to reproduce:
> import java.io.*;
> public class Test {
> public static void main(String args[]) throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
>
> new FileOutputStream(f, true).getChannel().tryLock();
>
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") +
> File.separator +
> "bin" +
> File.separator +
> "java";
> if(args.length == 0) {
> Process p = Runtime.getRuntime().exec(new String[] { javaCmd,
> "-cp",
> System.getProperty("java.class.path"),
> "Test", "foo" } );
>
> String line;
> InputStream is = p.getInputStream();
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
> Steps to reproduce:
> 1. Build Harmony j2se subset as described in README.txt.
> 2. Compile Test.java using BEA 1.4 javac
> > javac Test.java
> 3. Run java using compatible VM (J9)
> > java Test
> Output :
> java version "1.4.2_04"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32,
> Native Threads, GC strategy: parallel)
> locked OK
> Child prints: locked OK
> Output in Harmony:
> locked OK
> <here test hangs>
> JUnit test:
> ---------------FileLockTest.java------------
> import java.io.*;
> import junit.framework.*;
> public class FileLockTest extends TestCase {
> static boolean childVM = false;
> public static void main(String[] args) {
> childVM = args.length > 0;
> junit.textui.TestRunner.run(FileLockTest.class);
> }
> public void testFileLock() throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
> new FileOutputStream(f, true).getChannel().tryLock();
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") + File.separator
> + "bin" + File.separator + "java";
> if (!childVM) {
> Process p = Runtime.getRuntime().exec(
> new String[] { javaCmd, "-cp",
> System.getProperty("java.class.path"),
> this.getClass().getName(), "foo" });
> String line;
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Closed: (HARMONY-246)
java.nio.channels.FileChannel.tryLock() should be non-blocking
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/jira/browse/HARMONY-246?page=all ]
Tim Ellison closed HARMONY-246:
-------------------------------
Verified by Anton.
> java.nio.channels.FileChannel.tryLock() should be non-blocking
> --------------------------------------------------------------
>
> Key: HARMONY-246
> URL: http://issues.apache.org/jira/browse/HARMONY-246
> Project: Harmony
> Type: Bug
> Components: Classlib
> Environment: Windows, Linux
> Reporter: Anton Luht
> Assignee: Tim Ellison
> Attachments: Harmony-246.txt
>
> j2se 1.4.2 spec for java.nio.channels.FileChannel says:
> tryLock(..)
> Attempts to acquire a lock on the given region of this channel's file.
> This method does not block. An invocation of this always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown.
> in Harmony code this method blocks
> Suggested fix (naive): always use O_NONBLOCK in fcntl
> Code to reproduce:
> import java.io.*;
> public class Test {
> public static void main(String args[]) throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
>
> new FileOutputStream(f, true).getChannel().tryLock();
>
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") +
> File.separator +
> "bin" +
> File.separator +
> "java";
> if(args.length == 0) {
> Process p = Runtime.getRuntime().exec(new String[] { javaCmd,
> "-cp",
> System.getProperty("java.class.path"),
> "Test", "foo" } );
>
> String line;
> InputStream is = p.getInputStream();
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
> Steps to reproduce:
> 1. Build Harmony j2se subset as described in README.txt.
> 2. Compile Test.java using BEA 1.4 javac
> > javac Test.java
> 3. Run java using compatible VM (J9)
> > java Test
> Output :
> java version "1.4.2_04"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32,
> Native Threads, GC strategy: parallel)
> locked OK
> Child prints: locked OK
> Output in Harmony:
> locked OK
> <here test hangs>
> JUnit test:
> ---------------FileLockTest.java------------
> import java.io.*;
> import junit.framework.*;
> public class FileLockTest extends TestCase {
> static boolean childVM = false;
> public static void main(String[] args) {
> childVM = args.length > 0;
> junit.textui.TestRunner.run(FileLockTest.class);
> }
> public void testFileLock() throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
> new FileOutputStream(f, true).getChannel().tryLock();
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") + File.separator
> + "bin" + File.separator + "java";
> if (!childVM) {
> Process p = Runtime.getRuntime().exec(
> new String[] { javaCmd, "-cp",
> System.getProperty("java.class.path"),
> this.getClass().getName(), "foo" });
> String line;
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Commented: (HARMONY-246)
java.nio.channels.FileChannel.tryLock() should be non-blocking
Posted by "Anton Luht (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/jira/browse/HARMONY-246?page=comments#action_12377742 ]
Anton Luht commented on HARMONY-246:
------------------------------------
Tim,
Thanks, the problem is not reproduced any more.
> java.nio.channels.FileChannel.tryLock() should be non-blocking
> --------------------------------------------------------------
>
> Key: HARMONY-246
> URL: http://issues.apache.org/jira/browse/HARMONY-246
> Project: Harmony
> Type: Bug
> Components: Classlib
> Environment: Windows, Linux
> Reporter: Anton Luht
> Assignee: Tim Ellison
> Attachments: Harmony-246.txt
>
> j2se 1.4.2 spec for java.nio.channels.FileChannel says:
> tryLock(..)
> Attempts to acquire a lock on the given region of this channel's file.
> This method does not block. An invocation of this always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown.
> in Harmony code this method blocks
> Suggested fix (naive): always use O_NONBLOCK in fcntl
> Code to reproduce:
> import java.io.*;
> public class Test {
> public static void main(String args[]) throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
>
> new FileOutputStream(f, true).getChannel().tryLock();
>
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") +
> File.separator +
> "bin" +
> File.separator +
> "java";
> if(args.length == 0) {
> Process p = Runtime.getRuntime().exec(new String[] { javaCmd,
> "-cp",
> System.getProperty("java.class.path"),
> "Test", "foo" } );
>
> String line;
> InputStream is = p.getInputStream();
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
> Steps to reproduce:
> 1. Build Harmony j2se subset as described in README.txt.
> 2. Compile Test.java using BEA 1.4 javac
> > javac Test.java
> 3. Run java using compatible VM (J9)
> > java Test
> Output :
> java version "1.4.2_04"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32,
> Native Threads, GC strategy: parallel)
> locked OK
> Child prints: locked OK
> Output in Harmony:
> locked OK
> <here test hangs>
> JUnit test:
> ---------------FileLockTest.java------------
> import java.io.*;
> import junit.framework.*;
> public class FileLockTest extends TestCase {
> static boolean childVM = false;
> public static void main(String[] args) {
> childVM = args.length > 0;
> junit.textui.TestRunner.run(FileLockTest.class);
> }
> public void testFileLock() throws Exception {
> File f = new File("abcd");
> f.deleteOnExit();
> new FileOutputStream(f, true).getChannel().tryLock();
> System.err.println("locked OK");
> String javaCmd = System.getProperty("java.home") + File.separator
> + "bin" + File.separator + "java";
> if (!childVM) {
> Process p = Runtime.getRuntime().exec(
> new String[] { javaCmd, "-cp",
> System.getProperty("java.class.path"),
> this.getClass().getName(), "foo" });
> String line;
> BufferedReader input = new BufferedReader(new InputStreamReader(p
> .getErrorStream()));
> while ((line = input.readLine()) != null) {
> System.err.println("Child prints: " + line);
> }
> input.close();
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira