Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • zConcurrentModificationException


    Scorpius

    Recommended Posts

    Why does it have to be on dreambot ??? Its a general java programming practice, just google concurrency in java lol

     

    What I mean is, the effort you spend on criticizing can be spent on something more productive.

    Link to comment
    Share on other sites

    What I mean is, the effort you spend on criticizing can be spent on something more productive.

    not rlly, it didnt take any effort for me to type that comment

    Link to comment
    Share on other sites

    Just use a fori loop, the CurrentModificationException is thrown because you are editing the List in a for-each loop which uses an iterator. The iterator checks if something changed on every iteration, meaning as soon as you remove or add something the next iteration will throw this error. Using a fori loop you evade this iterator being used resulting in no error being thrown.

    Link to comment
    Share on other sites

    Just use a fori loop, the CurrentModificationException is thrown because you are editing the List in a for-each loop which uses an iterator. The iterator checks if something changed on every iteration, meaning as soon as you remove or add something the next iteration will throw this error. Using a fori loop you evade this iterator being used resulting in no error being thrown.

    But removing from the list while the loop is running somewhere still throws an exception, I'd solve it the same way I am solving it now

    Link to comment
    Share on other sites

    But removing from the list while the loop is running somewhere still throws an exception, I'd solve it the same way I am solving it now

    1. Stop using for-each loops and use fori instead
    2. If you are multi-threading and accessing this list from multiple Threads use synchronized blocks eventhough you should be fine only using fori
    Link to comment
    Share on other sites

     

    1. Stop using for-each loops and use fori instead
    2. If you are multi-threading and accessing this list from multiple Threads use synchronized blocks eventhough you should be fine only using fori

     

    I'll definitely be doing those very soon, thank you fella!

    Link to comment
    Share on other sites

    just use List#addAll

     

    avoiding iterator alone isnt thread safe.  you still should use a concurrent collection or synchronized block.  a concurrent collection makes more sense in this case.  CopyOnWriteArrayList (or ConcurrentLinkedQueue if u dont need indexed access)

    Link to comment
    Share on other sites

    just use List#addAll

     

    avoiding iterator alone isnt thread safe.  you still should use a concurrent collection or synchronized block.  a concurrent collection makes more sense in this case.  CopyOnWriteArrayList (or ConcurrentLinkedQueue if u dont need indexed access)

    I'm adding/removing/reading at the same time on 3 different threads, still thinking about approaches tbh but every answer in here is a step forward.

    Link to comment
    Share on other sites

    • 2 weeks later...

    I'll be writing a tutorial on concurrency/object locking/mutex in the general programming section this week, if you really intend to learn

    where's ur guide big mouth

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.