1 Reply Latest reply on Aug 23, 2012 12:09 PM by Bernhard Anzeletti

    threads concurrency issue while writing to text files

    Guy de P. Newbie

      Hi everybody,

       

      I'm using JBoss 5 with EJB3.0 to develop an application that needs among other things to read and write in a simple text file.

      My problems is how do i do to prevent multi threading / threads concurrency for theses operations.

       

      The write/read operations are perform from classes that there are annoted @Local

       

      Bests regards,

       

      Guy

        • 1. Re: threads concurrency issue while writing to text files
          Bernhard Anzeletti Newbie

          Excellent question since file I/O is not supported by JEE. As far as I percieve the situation synchronization depends on you, the application developer. There used to be some JCA adapters for File I/O including transation (isolation) support, but since they came by commercial licence I've never tried those by myself. Maybe meanwhile things have improved...

           

          My considerations so far include:

          1) provide a file server EJB .- maybe a @Singleton - that grants file access to clients and uses a database (JTA)  to manage locks on files

          2) make a CDI @Conversation or @Session the client of the file server

          However, doing this at professional quality seems to be a tremendous amount of work (can more than one client concurrently read a file? file renames? stale locks? @Rollback support? ....). This is where I quit pursuing this concept.

          On the other hand, modern databases all provide "BLOB"s so a file system can easily be emulated by a database... not the perfect match of technologies, but much simpler.