MYSQL cuse laggs

Discussion in 'Plugin Development' started by matanrak, Jul 17, 2014.

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

    matanrak

    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:
     
  2. Offline

    fireblast709

    matanrak don't run MySQL code on the main thread
     
  3. Offline

    matanrak

    where should i run it?
     
  4. Offline

    Traks

    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.
     
  5. Offline

    matanrak

    ok i can't use a task use i am trying to get kills....
     
  6. Offline

    Giant

    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! :D
     
  7. Offline

    matanrak

    can you please show me???? the code just lags when i kill a mob
     
  8. Offline

    mythbusterma

    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.
     
  9. Offline

    lualzockt

    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
      }
    
    });
    
     
  10. Offline

    mythbusterma

    Uh....no, it wouldn't. Read what the "synchronized" keyword does and come back: http://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html
     
    TheSpherret likes this.
  11. Offline

    matanrak

    wait but how can i use @eventhandler or an event triggered something inside a buckeye run task??
     
  12. Offline

    stonar96

    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
     
Thread Status:
Not open for further replies.

Share This Page