Solved Volatile and Synchronous Methods?

Discussion in 'Plugin Development' started by ColonelHedgehog, Nov 18, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ColonelHedgehog

    When would a volatile method be useful in Bukkit? Would a synchronous method be helpful when accessing a method from an asynchronous runnable?

    This might be a stupid question, but I've never needed to use them before, and I'm wondering when would be a good/more efficient time to do so.
     
  2. Offline

    Rocoty

    A volatile method would never be useful, as there is no such thing as a volatile method. Volatile can only be applied to fields. Assuming you mean synchronized methids and not synchronous, the oracle tutorials pretty much covers all the basics of concurrency. Have a look https://docs.oracle.com/javase/tutorial/essential/concurrency/

    Short answer: it depends.
     
  3. Offline

    AoH_Ruthless

    ColonelHedgehog
    Volatility and synchronization are two concepts in multi-threaded Java. While this is important in practical Java applications, the average Bukkit developer will almost never use these. If your plugin is managing/creating several threads, volatile as a keyword guarantees you visibility of the variable across threads. This means that reading/writing is visible through different threads. Synchronizing is a strategy for prevention of thread interference and memory consistency in the event of multiple threads. Synchronization does pose problems with liveness and speed, however.

    Like I said, if you only have one thread, both of these are relatively useless.
     
  4. Offline

    ColonelHedgehog

    Understood. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page