Closed FloydATC closed 9 years ago
What JRE are you using?
I suspect a faulty build. Did you build it yourself?
@FloydATC, why are we using concurrent hash maps anyway?
Both the test and production servers run java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64 Just downloaded the plugin, no recompile. ConcurrentHashMap is necessary because of multithreading, it takes care of all the nasty semaphore/locking stuff so we won't have to.
If I remember correctly, v1.94 was built using Oracle's JDK. Does the problem persist if you build using the JDK corresponding to your JRE?
In what other threads are the hash maps accessed?
A quick comparison of the Java SE 8 and 7 javadocs reveals the cause of the problem: The return type of ConcurrentHashMap<K, V>.keySet()
has changed from Set<K>
in version 7 to ConcurrentHashMap.KeySetView<K, V>
in version 8. This should be a compatible change though. However, v1.94 was built using JDK 8 for JRE 7. See link.
In Minecraft there are two threads per player; one to handle networking and one dealing with in-game events such as combat, block interaction etc. These threads make callbacks into the various plugins, meaning that two or more players may run plugin code simultaneously. Because of this, all plugins must be thread-safe. Plugins that utilize non-thread-safe classes (such as HashMap instead of ConcurrentHashMap) will crash immediately if accessed simultaneously by more than one thread (=player).
I use a JDK7 environment for all plugin related work, because I couldn't get the code to compile on JDK8. Looks like you found one of the main reasons. I don't know if changing the syntax and building on JDK8 will cause issues on JRE7, my guess is it will work just fine. Why they would go and change a perfectly good syntax is beyond me.
The interface wasn't changed, it was extended. Thus the code written for JDK 7 will also compile on JDK 8. The new return type is derived from the old one.
No, it was changed. In the most evil way possible. The code will compile using JDK8 but crashes spectacularly when executed in a JRE7 environment because .keySet() no longer returns an iterable "Set" object but rather a "ConcurrentHashMap.keySetView" object which doesn't have the method needed for JRE7 to iterate through the set. https://bz.apache.org/bugzilla/show_bug.cgi?id=55554 Seems I'm not the only one stumped by this record breaking stupidity which seems so integral to everything Java related. Meanwhile, I have no idea how to solve this so I'll go back to building on my Linux laptop with JDK7.
Problem solved. JDK8 can be used but you must set "compliance level 1.7" and then install and select JRE7 to be used when compiling. The procedure has been tested successfully and is described here: http://forums.atc.no/index.php?topic=1868.0 Case closed.