I got a mysql code that every time you kill a mob it gives you tokens in the mysql database but every time i kill a mod it lags. CODE:
Either use the Bukkit thread pool by scheduling an async task, or create one yourself. Make sure you aren't using any objects from Bukkit, CraftBukkit and net.minecraft.server as they aren't thread safe. Accessing them might work 95% of the time, but the other 5% could have a horrible outcome.
You can still use them. What you can do is simply call the async task by the command, supply it with required data, and have the async task call a sync(!) task when it received the data from MySQL. This way you will not have the server lag, unless it is of course caused by your code!
Sure: Code: Bukkit.getScheduler().runTaskAsynchronously(JavaPlugin, new Runnable () { @Override public void run() { // do stuff Bukkit.getScheduler().runTask(JavaPlugin, new Runnable() { @Override public void run () { // run code on the main thread to notify or update }); }); That's the simplest implementation of it.
Probably a syncronzied method should work here. Code: Bukkit.getScheduler().runTaskAsyncronly (new Runnable ((){ public void run (){ // your stuff goes here update (); } synchronized voud update (){ // bukkit api calls } });
Uh....no, it wouldn't. Read what the "synchronized" keyword does and come back: http://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html
My opinion is that you should lean java first befor you code plugins, because it seems like you dont understand what this does, you should place this code in the event instead of your mysql code