• J. Paul Morrison

    I have changed the name setDealockTestOn to setDeadlockTestOn, and replaced the setting for deadlockTest in a couple of test cases to use the getter, as I was getting compile errors. Will try committing these - will this result in conflict later?

    I note that the getter and setters for this boolean are all synchronized - is this necessary?

  • Guus Bonnema

    Guus Bonnema - 2013-11-17

    Hi Paul,

    Typo & test programs
    I found the same typo and changed it. And, I did not check the tests yet. First I need to make sure that Network is indeed thread safe.

    Is synchronized necessary?
    Yes, every mutable variable that is not itself threadsafe, and shared accros threads needs some kind of protection. We can protect simple fields with a synchronized, because their get or set will be very fast and that doesn't endanger throughput or scalability. The synchronized makes sure that the resulting updates are visible in all threads using the item.

    If we do not synchronize, a peeking or updating thread could see an invalid value, no value at all, a stale value or the correct value. This is all dependent on JVM runtime optimizations. Often such a concurrency error will not show for years, until strange things start to happen when under heavy load.

    Only if we are sure a mutable field will never cross thread borders, can we leave synchronized out. If we know only one thread updates and the others only peek, then you can risk defining it volatile.

    Otherwise, even for deadlocktest I would just synchronize. Probably in production you would only use this if you have trouble, I suspect.

    Regards, Guus.

  • J. Paul Morrison

    That makes sense! Thx. Paul


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks