FileLock Doesn't Work Across Network

I have found a case in which FileLock doesn't work. I'm trying to use FileLock to prevent two instances of the same process to run simultaneously on different machines (or the same machine) on the network. I actually saw two processes, one on each of two Linux machines obtain a lock on the same file at the same time.
Can I be sure that FileLock is calling fcntl and not flock (which wouldn't work over the network)?
Is there any way to fix this or get around it??
Here is the relevant code:
try{
     File lockFile = new File(getLockFilename());
     lockFile.createNewFile();  // Throw out the boolean return value; it doesn't matter if this succeeded.
     FileChannel fc = new FileOutputStream(lockFile).getChannel();
     fileLock = fc.lock();
catch (FileLockInterruptionException flie){
     // Allow this one.
catch (IOException ioe){
        // Report the exception, release the lock if obtained and exit.
// Code executed while the file is locked includes setting up and registering an RMI server object.
try{
     fileLock.release();
catch (IOException ioe){
     logger.warn("Unable to relase file lock:  " + ioe.getClass().getName() + ":  " + ioe.getMessage());
}

I suppose when you say "across network", you mean via
nfs?Yes.
Have each machine check some central point (or all
other nodes) for the existence of a server. Of course
there could be some synchronization problems, so you
might check several times. Even if the remote
interface is successfully exported, have it check one
final time to ensure. To be paranoid, you could have
it check often.We have a strong requirement not to have a central server, which has made coding this a headache. It would be pretty unacceptable to query every machine on our network (most of which probably aren't running any related process at any one time and are probably running other jobs) any time someone wants to start one of these processes on any machine. (There could be hundreds of these processes running at once with different parameters; it's just that no two with the same parameters are allowed to run at once. Each of these will act as a separate RMI server so other processes can communicate with the running process for other purposes besides just determining whether it is running.) A registry can only contain objects on one machine, right? Or can I somehow bind everything on the same host even though that's not where the objects are?? I am already writing the name of the successful host for one parameter set to a file and barring other processes with the same parameters from executing if looking up the process on that host succeeds. This works in most cases, but there is a race condition if two processes start around the same time and both read the file before either has written its host name there. That's why I'm trying to use a file lock on a different file so the read-bind-write sequence happens while the file is locked.

Similar Messages

  • Mac connects to wifi, but internet doesn't work. Network diagnostics shows problem starts at ISP. All software is updated and all other devices are able to effectively use the wifi source.

    Mac connects to wifi, but internet doesn't work. Network diagnostics shows problem starts at ISP. All software is updated and all other devices are able to effectively use the wifi source.

    Hi, KK93. 
    Sometimes a simple power cycle of the router and Mac can resolve the issue.  However, try the steps in the article below to troubleshoot the Wi-Fi issue with your MacBook.
    Troubleshooting Wi-Fi issues in OS X
    http://support.apple.com/kb/HT4628
    Also, see the article below to make sure the router setting have been optimized for performance.
    iOS and OS X: Recommended settings for Wi-Fi routers and access points
    http://support.apple.com/kb/HT4199
    Cheers,
    Jason

  • Finder sidebar doesn't work for networking?

    Does anybody else find that the sidebar in finder doesn't work when you network your computer to a pc network? I SEE the file servers when I click on "all" but when I double click on one of them it always says "connection failed". The only way I can access the network is to go to "Go" then "connect to server" then type in smb://ipaddress and have the server directly mounted to desktop (after changing finder preferences to show mounted volumes on desktop). Does the finder sidebar just not work then in leopard or am I doing something wrong?

    When you click on it, it will try and log on as user guest with no password. This will nearly always fail on a windows box.
    top right of the window pain there should then appear an option to 'connect as', click this and type in a valid username and password. Tick the box to add it to your keychain and it should then always connect when you click on the sidebar.

  • FileLock doesn't work in UNIX (solaris)

    Hi all,
    I have a piece of code which writes to xml file and before that locks the file to prevent two users writing in same file in same time.
    This code works perfectly on my windows environment (Eclipse and windows 2000) but as soon as I put jar file in UNIX (SOLARIS) it doesn�t work and two clients can change at same time!
    Anyone has an idea what is going on?
    Note: I put sleep just to be able to make a delay so I can try to have access from second client session to test my lock
    Following is my code:
      public synchronized void commitConfiguration() throws ConfigurationDataException
          try {     
              // Get a file channel for the file
              File file = new File(uri);
              FileOutputStream outputStream = new FileOutputStream(file);
              FileChannel  channel = outputStream.getChannel();
              FileLock lock = fileLock(channel);
              if(lock != null) {
                  try {
                      processCommit(outputStream);
                      Thread.sleep(8000);
                  }finally {
                      Thread.sleep(8000);
                      lock.release();
                      channel.close();
              //reload the configuration
              refreshConfiguration();                            
        } catch (Exception e1) {       
            throw new ConfigurationDataException("Cannot commit file, because: " + e1.getMessage());
      private static FileLock fileLock( FileChannel  channel) throws IOException {
          // Use the file channel to create a lock on the file. This is a share lock not exclusive so
          // other users can still read but not set
          // This method blocks until it can retrieve the lock.
          //FileLock lock = channel.lock(0L, Long.MAX_VALUE, true);
          // Try acquiring the lock without blocking. This method returns
          // null or throws an exception if the file is already locked.
          FileLock lock =null;
          try {
              lock = channel.tryLock();
          } catch (OverlappingFileLockException e) {
              // File is already locked in this thread or virtual machine
          if(lock == null) {
              lock = channel.lock();
          return lock;     
      }Thanks,

    So what should we do to have the file locked?
    The Issue is I have one shared file system which all
    of my servers (it is a HA system which there are two
    from each server) having access to same file and I
    want them to be in synch, so I am trying to lock the
    file so no body even from other JVM (second server)
    cannot edit the file at the same time.
    Is there any way to handle this issue with this
    feature of java I mean FileLock and Channel API?Do the Java programs in the other servers also have the code to try and lock the file? Although unix has advisory locks, from what I have read, they should still work as long as you make sure all the Java programs that access the file attempt to get the lock. If any non-Java programs are using the file then they to would need to try and lock the file (not sure if they would play nice with the Java programs).

  • IMessage doesn't work across multiple devices

    I updated my iPad mini and my iPhone 4S to iOS 6.1 and now iMessage no longer works across both devices. When my friends text my phone, it doesn't show up on their chat box on my iPad mini. If they message my iPad mini through my email, it doesn't show up on my iPhone. Please help, thanks!

    Nikki
    Under settings my iPad Mini (running on IOS 6.1) is showing the following:
    Settings> Messages>Send and Receive>  Iphone number and three email addresses... exactly the same as my Iphone 4 running IOS 6.
    It's not an IOS 6 issue.
    1. Try reset of your iPadmini - hold the off/on and home button until it goes black and release whrn you get to the Apple icon.  Log back in and see if you can enter your number in iMessage.
    2. Try disabling imessage on your Iphone and then enabling it
      Then go to your ipad mini and do the same.
    Let us know what happens.
    Cheers

  • HP Laserjet p1505n doesn't work over network with Yosemite

    Ever since upgrading the machines in my house (Mac Pro, iMac, MBPretina, MBAir) to Yosemite, I have not been able to use the network attached Laserjet p1505n that used to work flawlessly under 10.9.  It doesn't appear in the printer tab in System Prefs where it used to pop up.  Anyone have any experience with this?  The printer will install via USB just fine on the Mac Pro, MBPRetina, etc.  Thanks!

    To see the printer in the Default view of the Add printer window, a protocol called Bonjour is used by the printer and Mac. This protocol is having issues for some users who have upgraded to Yosemite. Until the issue is resolved you may be able to use one of the IP protocols to connect to the networked printer. To do so you will need to find the IP address being used by the printer. If the LJ-P1505n has a control panel, you may be able to generate a report showing the network settings.
    Once you have the IP address you can open Printers & Scanners and click the plus button to add a printer. Then click on the IP icon and enter the IP address of the HP in the Address Field. In the Protocol field, change to HP Jetdirect-Socket and in the Queue field, leave this blank. You can then change the Name from the IP address to LJP1505n and in the Use menu, select the P1505n printer. Click the Add to complete the printer creation and then see if you can print.

  • Check In/Out doesn't work on network drive?

    My company has used DW's check in/check out functionalities just fine for years, but before now the local copies of a site's files had been stored on each user's Mac's harddrive. I've been working on relocating those local copies to a single network drive that everyone can access so we're all working from the same local copies; most everything's going great except it looks like the check in/out functions are no longer working. It looks like the only indication I can see now in the FTP view is a green check on the remote files pane when something's checked out– the local copies don't show lock or check icons any longer.
    Given that the only change has been moving the local files over to the network drive, I have to assume DW's check in/out (or at least however I have settings set now) doesn't play nice when the local files live on a network drive. Has anyone run into this issue, and is there a fix for it?
    Thanks,
    J

    @Zabeth69:
    Yep, a new site definition's been set up and I've double-checked that the "local files" setting is pointing to the shared network server as the new local folder.
    @Nadia-P:
    At first I didn't think that link had anything that I didn't already know, and then saw these two bullets:
    •  The local root folder for this defined site must be on the local hard drive of a workstation.
    •  Your local root folder should not be shared or on a mounted drive.
    So in short, I suppose those answer my question, but they don't actually say *why* that is– it's hard to believe that the checking feature is limited to a literal local drive, and not a network drive. Seems odd. I'm going to poke around some more and try and figure out why that is, but I'd be grateful if anyone happens to know why in the meantime...
    J

  • Time Machine works across network?

    My work is considering making the jump to Leopard Server. I'm mostly interested in this page: http://www.apple.com/server/macosx/features/filesharing.html
    Is it true that Time Machine on Leopard Server will automatically backup all my connected users hard drives? With that in place, there's no need for each workstation to run Time Machine locally with a locally connected Time Machine HDD?
    Or does Time Machine on Leopard Server work like normal Time Machine and only backups what on my server's local drives to another server drive?

    While the server can be set to be the destination for client's needs for a Time Machine destination, so can any other Leopard client computer.
    I would need to mention though that I've just opened Leopard Server and am immediately disappointed that Time Machine will not work in Advanced Configuration.
    FTP requires Advanced Configuration and so I am stuck without one or the other.

  • SendMail doesn't work outside network

    I need to enable a mail server in Solaris 11. I'm setup sendmail, procmail, imap and pop3. The system's status:
    online    
    dic_01   svc:/network/sendmail-client:default
    online    
    20:16:19 svc:/network/smtp:sendmail
    online    
    13:24:06 svc:/network/imap/tcp:default
    online    
    13:24:06 svc:/network/pop2/tcp:default
    online    
    13:24:07 svc:/network/pop3/tcp:default
    I can to send mails within network, the mail is sent and received but I can't to send and to receive mails outside network.
    Thank you in advance for your help.
    Jose.

    Sounds like local_only might be set to true instead of false.  True is the default.
    This should help you.
    http://fixunix.com/solaris/142775-netservices-limited.html
    alan

  • In an InDesign book, how can I create links that work across documents?

    The hyperlinking works fine when it is contained within a single document in a book, however doesn't work across documents.

    Do you mean cross-references? You can do those, but they are known to be "fragile" and unreliable.

  • Netboot doesn't work; DHCP issue?

    I'm setting up NetBoot for the first time on my Leopard Xserve, trying to do NetInstall on some G4 clients.
    Imaging seemed to work fine and the client boots as far as the grey apple screen - but then the client crashes with "You need to restart your computer now".
    The log looks like this:
    May 19 03:42:29 blue bootpd[64401]: can't open /etc/bootptab
    May 19 03:42:29 blue bootpd[64401]: server name blue.pvpa.com
    May 19 03:42:29 blue bootpd[64401]: interface en0: ip 192.168.1.15 mask 255.255.255.0
    May 19 03:42:29 blue bootpd[64401]: subnets: Failed to convert 'router': Invalid IP address
    May 19 03:42:29 blue bootpd[64401]: bsdpd: re-reading configuration
    May 19 03:42:29 blue bootpd[64401]: bsdpd: shadow file size will be set to 48 megabytes
    May 19 03:42:29 blue bootpd[64401]: bsdpd: age time 00:15:00
    I'm not running DHCP service on my Xserve - DHCP is coming from the router. The client does seem to be getting an IP address, according to Server Admin --> NetBoot --> Clients. Do I need to do something different with DHCP on the Xserve, and if so what?
    Also, I tried creating /etc/bootptab by hand but that didn't make a difference either.

    May 19 03:42:29 blue bootpd64401: subnets: Failed to convert 'router': Invalid IP address
    This might be an issue... I've never seen this log before. Is your server on a different subnet then the clients you are attempting to boot? NetBoot doesn't work across subnets without some extra work.

  • Hosting doesn't work

    hosting doesn't work across our projects in some of the links:
    ex. http://www.backstageny.com/coupons.html

    Tks, it's funny, after re-upload one page start working but another stop - wierd.
    I did check the status, but they didn't fix all sites I guess.
    http://status.businesscatalyst.com

  • [SOLVED] network randomly doesn't work after reboot (e100)

    Hi
    Lately I have some weird issues with network. I shutdown computer during night, so basicly I reboot it at least once per day and every now and then without any pattern network doesn't work at all and so far only solution I have found is to reboot (again).
    Before anything else I'm sure it's not hardware problem, since other OS on same computer don't have any issues, neither is router since other devices in network from laptops to mobile phones work flawless.
    Relevant info and what I have found so far (not everything is copy/pasted so there may be some typos):
    $less rc.conf (network part)
    eth1="eth1 192.168.1.242 netmask 255.255.255.0 broadcast 192.168.1.255
    INTERFACES=(eth1)
    gateway="default gw 192.168.1.1"
    ROUTES=(gateway)
    $ifconfig
    eth1 Link encap:Ethernet HWaddr 00:D0:B7:5A:7A:A9
    inet addr:192.168.1.242 Bcast:192.168.1.255 Mask:255.255.255.0
    UP BROADCAST MULTICAST MTU:1500 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:380 errors:0 dropped:0 overruns:0 frame:0
    TX packets:380 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:36154 (35.3 Kb) TX bytes:36154 (35.3 Kb)
    $route
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    192.168.1.0 * 255.255.255.0 U 0 0 0 eth1
    default 192.168.1.1 0.0.0.0 UG 0 0 0 eth1
    $ping 192.168.1.1
    PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data
    From 192.168.1.242 icmp_seq=2 Destination Host Unreachable
    So basicly network is dead, can't even ping router, cable connection is detected tho (lights are on). I have tried to restart newtork with /etc/rc.d/network stop/start, nothing. Only clue is dmesg.
    $dmesg
    Linux version 2.6.30-ARCH (root@T-POWA-LX) (gcc version 4.4.1 (GCC) ) #1 SMP PREEMPT Fri Jul 31 07:30:28 CEST 2009
    e100: Intel(R) PRO/100 Network Driver, 3.5.24-k2-NAPI
    e100: Copyright(c) 1999-2006 Intel Corporation
    e100 0000:03:07.0: PCI INT A -> Link[APC2] -> GSI 17 (level, low) -> IRQ 17
    e100 0000:03:07.0: PME# disabled
    e100: eth1: e100_probe: addr 0xfdfff000, irq 17, MAC addr 00:d0:b7:5a:7a:a9
    e100 0000:03:07.0: firmware: requesting e100/d101m_ucode.bin
    ADDRCONF(NETDEV_UP): eth1: link is not ready
    modrope -r e100 and then reloading it doesn't help either, but reboot does (once I had to reboot twice tho).
    Anyone with more clue and ideas then me, it's getting really annoying, it also kill whole KDE plasma-desktop for couple of minutes before plasmoids find out network is really down and I'm not really fan of morning "gamble". I can't pinpoint some hard date/update when this started to happening because like I said it's random but last couple of months should be quite accurate. Thanks in advance.
    EDIT: dmesg when network works:
    tilen@pikmin ~]$ dmesg | grep e100
    pci 0000:03:07.0: Firmware left e100 interrupts enabled; disabling
    e100: Intel(R) PRO/100 Network Driver, 3.5.24-k2-NAPI
    e100: Copyright(c) 1999-2006 Intel Corporation
    e100 0000:03:07.0: PCI INT A -> Link[APC2] -> GSI 17 (level, low) -> IRQ 17
    e100 0000:03:07.0: PME# disabled
    e100: eth0: e100_probe: addr 0xfdfff000, irq 17, MAC addr 00:d0:b7:5a:7a:a9
    Last edited by NoOrdinary (2009-09-05 09:47:20)

    I don't have anything special set at router but I doubt rc.conf play any role. I will try to set it up with dhcp (but I think I have tried that already) if there is any change.
    This morning I had to reboot twice, so new kernel didn't help. Fowler, what network card are you using, also e100 (well or some intel)? I dunno, should this be handed to the kernel team? If it will piss me enough one morning I'll just go and buy a new network card, just wanna be sure that will really solve the problem.
    UPDATE: OK, this is just silly. I remebered I have acctualy onboard LAN so I edited rc.conf and dived into the dust under my desk to move cable and there I found out it was acctual onboard in use all the time Now this dosen't make much sense to me anymore, when I can't get net up all the stuff in dmesg is e100 related. Anyway, I connected network to e100 and rebooted, suprise, same story. Dmesg reported again link was not ready. I edited rc.conf to
    INTERFACES=(eth0 !eth1)
    in case this has anything to do with proper timing at assigning whatever needs to be assigned to network cards at boot so I'm sure just 1 card with all info provided get's kicked in at boot. First reboot after that works, it dosen't prove anything yet but at leat it's some kind of progress in recognising proper cause.
    UPDATE 2: Nah, still happens. Googling for "no link during initialization" show a lot of familiar problems, almost all on nforce motherboards and mine is nforce too. I just don't get it why this mess seperate PCI network card. In any case it's extremely annoying.
    Last edited by NoOrdinary (2009-09-02 11:46:27)

  • The wifi at my school isn't very good. And I can't send iMessages through it. It works for some apps like score center and my radar app, but doesn't work for other apps like clash of clans and iMessage. How can I get it to work on that  wifi network

    The wifi at my school isn't very good. And I can't send iMessages through it. It works for some apps like score center and my radar app, but doesn't work for other apps like clash of clans and iMessage. How can I get it to work on my school wifi. I have an iPhone 4S on AT&T and iOS 7.04

    In a roaming network, your "main" router is the device that would require port mapping/forwarding to be configured in order to access the IP camera from the Internet. This router is also the one that would be provide the private IP address for the camera which you will want to be a static one.
    So as you described your network, the IP cameras should be getting an IP address or you assigned it a static one and this is the address that you would enter in the Private IP address (or equivalent depending on the router used) field when setting up port mapping.
    If you are not able to access this camera from the local network, then this should be troubleshot first.

  • HT4259 I have been trying for hours to extend my Extreme Gen 5 network with an Express Gen 2.  But no matter what I do or try, it doesn't work.  What does happen is my internet gets block somehow when the Express looks like it's set up and 'green' - no in

    I have been trying for hours to extend my Extreme Gen 5 network with an Express Gen 2.  But no matter what I do or try, it doesn't work.  What does happen is my internet gets blocked somehow when the Express is online and looks like it's set up perfect and 'green' - but no internet connection for anything even though the Extreme is green and the modem is good.  Once I disconnect the Express, everything is good again.
    I've tried LAN, WAN, though a switch, direct connect, Extreme set to Extend the network, the Express set to be an extension.  Most of the time I get an error trying to update the Express.  But when it seems to be set up perfect, the entire house can't get to the internet.  Just when it looks right, it is so wrong.
    If anyone can give me exact steps (e.g., "...from the Base Station menu, select the Restore Default Setting option" vice "...just restore the defaults..."), I would greatly appreciate it.  I'm left to the conclusion that the Express is faulty.  I've been using Airport Utility 6.2 from Mountain Lion on one computer and Airport Utility 5.6.1 from Snow Leopard on another computer (the latter give more control while the former just want you to 'forget' the Express).

    I finally got it working.  I was trying to set it up ethernet.  My biggest mistake was when the new Express came on, I did not select 'Continue' - I went straight to manual thinking that I would get the most setup options in manual mode.  So everything I initially tried always resulted in 'wireless'.  Even when I would update or restore default settings, the Express would not completely restart. Or sometimes I would get an error. So most of the time I had to unplug it.  So when it came back up, none of my changes were retained. But there were a lot of times when everything was green and appeared to be fine. But anytime the ethernet cable was plugged in, no more internet.
    So here's the weird part.  When I finally tried 'continue' (vice manual), I would get 4 options.  One would be 'ethernet' extended.  So I would select it, it gave me green lights, all looked good, and still the same problem.  This is when I got frustrated.  I thought I had exhausted all possible combinations.
    But somehow when trying continue again after another restore, I only got 3 options.  One was the same ethernet extended option (can't remember what the missing 4th one was).  And this time it worked - it gave me the big green circle with the checkmark saying it was successful.  I don't know what I did different, but I know now that it won't work if 4 options come up to choose from.  It will work if only 3 options come up.  And success if only verified by the big checkmark.  Had anyone anywhere said the checkmark declaring success is validation, then maybe I wouldn't have gone down so many rabbit holes thinking it should have been successful.
    As for which Airport Utility I prefer, 6.2 looks nice, but it would just ignore the Express and would want me to 'forget' it and would not let me edit it.  Airport Utility 5.6.1 was the one that I ended up using the most and finally had success with.  It still strikes me as odd that there is no manually way to pick ethernet, it can only be choosen following a 'restore defaults', and only from the 3-option list (the 4-option list had the same ethernet choice, but it no worky).
    Thanks for the response.  I really do appreciate it.
    Aiport Extreme Gen5 - internet access and router
    Airport Express Gen2 - connected via ethernet, extending my wireless
    - configured while connect directly to the Extreme, but now on a switch (16-port hub)
    Using Airport 5.6.1
    1) Restore Defaults from Base Station menu
    2) Following restart, Select Continue
    3) Of the 3 option presented, select 'ethernet.... extend network...'
      - if 4 options are present, may not work
    4) Wait for the green circle with the big white checkmark.
    5) Connected Express to the switch where a cable went to other end of house - works.
    Dead-zone went from 2mbps to 24mbps.
    I probably spent 4 hours chasing my tail in anger.  The correct way took about 5 minutes total.
    Thanks again.

Maybe you are looking for