Synchronized Code Access - NoLagg
How the cross-thread guard of NoLagg works
A simple introduction and description
Imagine you have a TODO list located on your refrigerator. Now you go to that list, look at it and read it line by line, after which you perform a task. What if a second person stands next to you and removes a line on this TODO list while you are still reading it? Or what if he writes a new line on this list?
This is what happens when two threads try to access the same 'Object' at the same time. This results in something called 'Concurrent Modification Exceptions', which basically means that an object (a collection in this case) got modified while it was expecting this object to stay the same.
The problem is, however, that the wrong plugin can be accused of this error! If the main thread is reading the player list and suddenly another thread removes a player, the main thread spits out that error while the thread that caused this in the first place, is ignored.
This is what NoLagg tackles. Whenever something that is to be called by the main thread ONLY is called by another thread, it logs a warning with all details needed to trace the cause back.
How these errors look like
12:48:39 [WARNING] Could not properly handle event PLAYER_TELEPORT: java.lang.IllegalAccessError: Synchronized code got accessed from another thread: com.cypherx.xauth.xAuth$2 at org.bukkit.event.player.PlayerListener.onPlayerTeleport(PlayerListener:0) at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:339) at org.bukkit.craftbukkit.entity.CraftPlayer.teleport(CraftPlayer.java:297) at org.bukkit.craftbukkit.entity.CraftEntity.teleport(CraftEntity.java:156) at com.cypherx.xauth.xAuth$2.run(xAuth.java:302) at org.bukkit.craftbukkit.scheduler.CraftWorker.run(CraftWorker.java:34) 12:48:39 [INFO] This error is logged only once: it could have occurred multiple times by now. 12:48:40 [INFO] Please contact one of the authors of plugin 'xAuth': CypherX
Looking at the stack trace reveals the thread that caused this:
at com.cypherx.xauth.xAuth$2.run(xAuth.java:302)
In this case, xAuth is acting up and is currently causing that issue. It's now up to the author of this plugin to resolve his mistake. These errors are only thrown once: it is possible that this error was thrown hundreds and hundreds of times. This can affect all other plugins dramatically: if you get a 'concurrent modification exception' or 'Array index out of range exception' in another plugin right after this error, then first check out the plugin that caused the synchronized code access error.
What if the plugin that it comes up with java.lang.IllegalAccessError: Synchronized code got accessed from another thread: com.cypherx.xauth.xAuth$2 in this example line is the nolagg plugin...? Isn't this plugin supposed to fix this, not cause it? This is also making my server unavailable, even from the computer it is running from.
@Suembeaux This plugin doesn't cancel the synchronized code access error-ed events anymore - it only logs them. NoLagg has nothing to do with those errors, it only logs them so you at least know of it happening. (how else can you explain people getting disconnected randomly, another thread is causing havoc!)
Anything that happens after that message is caused by the plugin displayed (Xauth), NoLagg does not change the outcome in any way.
EDIT
Misread. Yes, if it is NoLagg, then shame on me, I'll have to fix it. It happened a few times while there was a bug in the isChunkLoaded call in CraftBukkit and when it loaded chunks while fixing lighting. Bless this feature. :)
@bergerkiller Hi, After a while of my server being up (about 10 hours) I get huge lag spikes and by TPS fluctuates between 9 - 36. I ran the examine command while this was happening but did not know how to identify something unusual. Could you possibly tell me what plugin has gone rogue or what I may be doing wrong? At one point I was using up 3.6ghz of an i7 2600 (100% of one core) with only 9 people online O_O
I'm running #184 of Craftbukkit++
My exam file: http://www.2shared.com/file/mKgj1viD/2012_04_01-17_34_45.html
@godgodgodgo
I think ou can better p[ost this on the page of the exmine command
If the error is only thrown once, can it be logged to a file? I can't watch console 24 hours a day waiting for this to happen, and searching/finding through a massive server.log file is impractical. You might suggest chopping up the server.log file, but this is also not necessarily practical.