You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Yungwei Chen <yu...@resolvity.com> on 2012/09/29 05:20:19 UTC

[io] Are FileUtils and IOUtils thread safe?

Hi,

I would like to know if FileUtils and IOUtils are thread safe. Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [io] Are FileUtils and IOUtils thread safe?

Posted by sebb <se...@gmail.com>.
On 29 September 2012 13:39, Martin Gainty <mg...@hotmail.com> wrote:
>
> Hi Sebb
>
> public class FileUtils {
>
>     /**
>      * Instances should NOT be constructed in standard programming.
>      */
>     public FileUtils() {
>         super();
>     }
>
>     /**
>      * The number of bytes in a kilobyte.
>      */
>     public static final long ONE_KB = 1024;
>
>     /**
>      * The number of bytes in a megabyte.
>      */
>     public static final long ONE_MB = ONE_KB * ONE_KB;
>
>     /**
>      * The number of bytes in a 50 MB.
>      */
>     private static final long FIFTY_MB = ONE_MB * 50;
>
>     /**
>      * The number of bytes in a gigabyte.
>      */
>     public static final long ONE_GB = ONE_KB * ONE_MB;
>
>     /**
>      * An empty array of type <code>File</code>.
>      */
>     public static final File[] EMPTY_FILE_ARRAY = new File[0];
>
>     /**
>      * The UTF-8 character set, used to decode octets in URLs.
>      */
>     private static final Charset UTF8 = Charset.forName("UTF-8");
>
>     //-----------------------------------------------------------------------
>     /**
>      * Returns the path to the system temporary directory.
>      *
>      * @return the path to the system temporary directory.
>      *
>      * @since Commons IO 2.0
>      */
>     public static String getTempDirectoryPath() {
>         return System.getProperty("java.io.tmpdir");
>     }
>
> how is public static immutable?

The qualfiers public and static do not affect immutability.

The fields are final, and the objects themselves are immutable.

Note: final array elements are not immutable, however a zero-length
array has no elements, mutable or otherwise.

> how is public static threadsafe?

Immutable => threadsafe

> Martin Gainty
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
>
>
>
>
>> Date: Sat, 29 Sep 2012 12:49:57 +0100
>> Subject: Re: [io] Are FileUtils and IOUtils thread safe?
>> From: sebbaz@gmail.com
>> To: user@commons.apache.org
>>
>> On 29 September 2012 04:20, Yungwei Chen <yu...@resolvity.com> wrote:
>> > Hi,
>> >
>> > I would like to know if FileUtils and IOUtils are thread safe. Thanks.
>>
>> The classes themselves are immutable and so are thread safe.
>>
>> However, many of them use JVM classes that may not be thread safe.
>>
>> Also, methods that depend on the state of the file system may not be
>> immune to external influences.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: [io] Are FileUtils and IOUtils thread safe?

Posted by Martin Gainty <mg...@hotmail.com>.
Hi Sebb

public class FileUtils {

    /**
     * Instances should NOT be constructed in standard programming.
     */
    public FileUtils() {
        super();
    }

    /**
     * The number of bytes in a kilobyte.
     */
    public static final long ONE_KB = 1024;

    /**
     * The number of bytes in a megabyte.
     */
    public static final long ONE_MB = ONE_KB * ONE_KB;

    /**
     * The number of bytes in a 50 MB.
     */
    private static final long FIFTY_MB = ONE_MB * 50;

    /**
     * The number of bytes in a gigabyte.
     */
    public static final long ONE_GB = ONE_KB * ONE_MB;

    /**
     * An empty array of type <code>File</code>.
     */
    public static final File[] EMPTY_FILE_ARRAY = new File[0];

    /**
     * The UTF-8 character set, used to decode octets in URLs.
     */
    private static final Charset UTF8 = Charset.forName("UTF-8");

    //-----------------------------------------------------------------------
    /**
     * Returns the path to the system temporary directory.
     * 
     * @return the path to the system temporary directory.
     * 
     * @since Commons IO 2.0
     */
    public static String getTempDirectoryPath() {
        return System.getProperty("java.io.tmpdir");
    }

how is public static immutable?
how is public static threadsafe?

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.




> Date: Sat, 29 Sep 2012 12:49:57 +0100
> Subject: Re: [io] Are FileUtils and IOUtils thread safe?
> From: sebbaz@gmail.com
> To: user@commons.apache.org
> 
> On 29 September 2012 04:20, Yungwei Chen <yu...@resolvity.com> wrote:
> > Hi,
> >
> > I would like to know if FileUtils and IOUtils are thread safe. Thanks.
> 
> The classes themselves are immutable and so are thread safe.
> 
> However, many of them use JVM classes that may not be thread safe.
> 
> Also, methods that depend on the state of the file system may not be
> immune to external influences.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
 		 	   		  

Re: [io] Are FileUtils and IOUtils thread safe?

Posted by sebb <se...@gmail.com>.
On 29 September 2012 04:20, Yungwei Chen <yu...@resolvity.com> wrote:
> Hi,
>
> I would like to know if FileUtils and IOUtils are thread safe. Thanks.

The classes themselves are immutable and so are thread safe.

However, many of them use JVM classes that may not be thread safe.

Also, methods that depend on the state of the file system may not be
immune to external influences.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: [io] Are FileUtils and IOUtils thread safe?

Posted by Yungwei Chen <yu...@resolvity.com>.
No. 

-----Original Message-----
From: jcarman@carmanconsulting.com [mailto:jcarman@carmanconsulting.com] On Behalf Of James Carman
Sent: Monday, October 01, 2012 12:03 PM
To: Commons Users List
Subject: Re: [io] Are FileUtils and IOUtils thread safe?

Would you have two different threads attempting to write to the same file?

On Mon, Oct 1, 2012 at 12:55 PM, Yungwei Chen <yu...@resolvity.com> wrote:
> Specifically FileUtils.writeStringToFile(file, data, encoding, false), which in turn calls IOUtils.write().
> Thanks.
>
> -----Original Message-----
> From: Daniel Pitts [mailto:coloraura.com@gmail.com]
> Sent: Saturday, September 29, 2012 1:10 AM
> To: Commons Users List
> Subject: Re: [io] Are FileUtils and IOUtils thread safe?
>
> On 9/28/12 8:20 PM, Yungwei Chen wrote:
>> Hi,
>>
>> I would like to know if FileUtils and IOUtils are thread safe. Thanks.
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
> Thread safe in what way? Which methods? What are your use-cases?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [io] Are FileUtils and IOUtils thread safe?

Posted by James Carman <ja...@carmanconsulting.com>.
Would you have two different threads attempting to write to the same file?

On Mon, Oct 1, 2012 at 12:55 PM, Yungwei Chen <yu...@resolvity.com> wrote:
> Specifically FileUtils.writeStringToFile(file, data, encoding, false), which in turn calls IOUtils.write().
> Thanks.
>
> -----Original Message-----
> From: Daniel Pitts [mailto:coloraura.com@gmail.com]
> Sent: Saturday, September 29, 2012 1:10 AM
> To: Commons Users List
> Subject: Re: [io] Are FileUtils and IOUtils thread safe?
>
> On 9/28/12 8:20 PM, Yungwei Chen wrote:
>> Hi,
>>
>> I would like to know if FileUtils and IOUtils are thread safe. Thanks.
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
> Thread safe in what way? Which methods? What are your use-cases?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: [io] Are FileUtils and IOUtils thread safe?

Posted by Yungwei Chen <yu...@resolvity.com>.
Specifically FileUtils.writeStringToFile(file, data, encoding, false), which in turn calls IOUtils.write().
Thanks.

-----Original Message-----
From: Daniel Pitts [mailto:coloraura.com@gmail.com] 
Sent: Saturday, September 29, 2012 1:10 AM
To: Commons Users List
Subject: Re: [io] Are FileUtils and IOUtils thread safe?

On 9/28/12 8:20 PM, Yungwei Chen wrote:
> Hi,
>
> I would like to know if FileUtils and IOUtils are thread safe. Thanks.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
Thread safe in what way? Which methods? What are your use-cases?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [io] Are FileUtils and IOUtils thread safe?

Posted by Daniel Pitts <co...@gmail.com>.
On 9/28/12 8:20 PM, Yungwei Chen wrote:
> Hi,
>
> I would like to know if FileUtils and IOUtils are thread safe. Thanks.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
Thread safe in what way? Which methods? What are your use-cases?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org