Hi, I am trying to peruse lucene's Lock for my own purposes, I need to lock several java processes and I thought I could reuse the Lock stuff. I understand lucene locks work across jvm.
But I cannot make it work. I tried to reproduce my problem in a small class: public class SysLock { private static final Logger logger = Logger.getLogger(SysLock.class); private int id; public SysLock(int i) { id = i; } // public static void main(String[] args) throws Exception { // System.setProperty("org.apache.lucene.lockDir", "C:\\temp\\todel"); // SysLock l1 = new SysLock(1); // SysLock l2 = new SysLock(2); // // TransferThread t = l1.new TransferThread(l1); // t.start(); // TransferThread t2 = l2.new TransferThread(l2); // t2.start(); // // logger.info("Finished."); // } public static void main(String[] args) throws Exception { System.setProperty("org.apache.lucene.lockDir", "C:\\temp\\todel"); SysLock l1 = new SysLock(new Date().getSeconds()); TransferThread t = l1.new TransferThread(l1); t.start(); logger.info("Finished."); } private void forever() throws IOException { FSDirectory directory = FSDirectory.getDirectory("C:\\temp\\a", true); try { new Lock.With(directory.makeLock("COMMIT_LOCK_NAME"), COMMIT_LOCK_TIMEOUT) { public Object doBody() throws IOException { while (true) { System.out.println("i'm " + id); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } } }.run(); } catch (Exception e) { System.out.println(id + " could not get lock"); } } class TransferThread extends Thread { public TransferThread(SysLock sl) { this.sl = sl; } public void run() { try { sl.forever(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private SysLock sl; } } When I run the main() that is commented (that is, the lock works with two threads in the same jvm) it works ok, the second TransferThread cannot get the lock. But when I run the uncommented main() twice, both processes adquire a lock, even if only one lock file exists in the lockdir. Something I am missing probably.... Many thanks javi --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]