Page 2 of 2 FirstFirst 1 2
Results 11 to 15 of 15

Thread: Java Exception when Zlib is running

  1. #11
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,820

    Default

    And even if it wasn't newly allocated, it wouldn't matter. You can't make some other thread's local variables null by manipulating your thread's variables.

  2. #12
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,182

    Default

    static methods with immutable parameters are thread safe. static methods with mutable parameters are not. My first pass suggested some mutable parameters were being used and hence the code was not thread safe. My second pass, today, suggests my first pass was wrong since File and String are immutable and that covers most of the static calls.

    Edit: Once again I make a sweeping generalization that is not true as presented and fail to articulate the conditions and assumptions that will make it true. Move on. Nothing to see here.
    Last edited by fronobulax; 11-06-2018 at 03:14 PM. Reason: Correct the record.

  3. #13
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,820

    Default

    static methods with immutable parameters are thread safe. static methods with mutable parameters are not.
    Originally Posted by fronobulax View Post
    Both of those statements are false.
    Immutable parameters don't save you from clobbering class attributes that are currently being used by a different thread ...
    ... and mutable parameters don't prevent you from properly synchronizing (or even not doing anything potentially thread-unsafe in the first place).

    What is probably thread-unsafe is manipulation with DataFileCache.dataFileDataCache and DataFileCache.dataFileTimestampCache (The <tt>HashMap</tt> class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.).

    Maybe updateCache and getBytes should be synchronized on dataFileDataCache? And updateCache could maybe print a helpful error message if data==null, just to be safe? Because if that can happen, then getBytes *would* return null for that filename ....
    (it's also currently possible to dataFileDataCache.get(filename) while some other thread is in the middle of storing the data for that filename)

  4. #14
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,182

    Default

    Both of those statements are false.
    Originally Posted by xKiv View Post
    I obviously disagree but am fine with resolving that in PM or not at all. If my mistakes and our disagreement leads to someone fixing a problem and the problem something was thread-unsafe then I am content.
    You just vehemently agreed with me
    Originally Posted by Veracity View Post
    I agree with frono.
    Originally Posted by Veracity View Post

  5. #15
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,182

    Default

    I decided xKiv was making more sense than I was and implemented what I thought was his suggestion.

    r18985

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •