diff options
author | Andrew Su <[email protected]> | 2011-03-17 15:19:39 -0400 |
---|---|---|
committer | Andrew Su <[email protected]> | 2011-03-17 15:19:39 -0400 |
commit | c7f5a45be53186f7fe165f48214f4ae91ed1a5ff (patch) | |
tree | a147f107a3ab1594502a6aae2e5bb047215b0af3 /netx/net/sourceforge | |
parent | 8b14e30c2894902f33653ecac38332cb4bb84f11 (diff) |
Allow plugin and javaws to run concurrently, while maintaining locks on systems that only support exclusive locks.
Diffstat (limited to 'netx/net/sourceforge')
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java index 02b6381..98bb6f5 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -656,14 +656,21 @@ public class JNLPRuntime { FileInputStream is = new FileInputStream(netxRunningFile); FileChannel channel = is.getChannel(); - fileLock = channel.lock(0, Long.MAX_VALUE, true); + fileLock = channel.lock(0, 1, true); + if (!fileLock.isShared()){ // We know shared locks aren't offered on this system. + FileLock temp = null; + for (long pos = 1; temp == null && pos < Long.MAX_VALUE - 1; pos++){ + temp = channel.tryLock(pos, 1, false); // No point in requesting for shared lock. + } + fileLock.release(); // We can release now, since we hold another lock. + fileLock = temp; // Keep the new lock so we can release later. + } + if (fileLock != null && fileLock.isShared()) { if (JNLPRuntime.isDebug()) { System.out.println("Acquired shared lock on " + netxRunningFile.toString() + " to indicate javaws is running"); } - } else { - fileLock = null; } } catch (IOException e) { e.printStackTrace(); |