Best way to handle connections?

Discussion in 'Spigot Plugin Development' started by ultracakebakery, Jun 8, 2016.

  1. Hello
    I'm working on a plugin that currently opens->closes the connection when needed.
    It works but its really slow (because every time i call a function it opens a new connection(which causes a lagg-spike to occur for a couple seconds)).

    So i searched on the forums for some fixes and the only fix i could find was creating a connection Pool but i have no-idea how to make one. Also people say that u can leave the connection open but other people tell the opposite.

    So i'm kinda stuck ATM, i hope u guys could give me some advice.

    - Jack
     
  2. Try to open your connection in a different thread, so that the main thread (Server) won't freeze.

    You can create a new thread like this:
    Code (Text):
    Thread connectionThread = new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            // your code here
        }
    });
    You can call connectionThread.start(); to run it whenever you want.
     
  3. What I do when handling sql is wrap any code in a BukkitRunnable, and run the task asynchronously
     
  4. Can u spoon feed me please? i have tried it myself a couple times but i keep missing my mouth if u know what i mean....
     
    • Funny Funny x 2
  5. will a fork do?
     
    • Funny Funny x 1
    • Winner Winner x 1
  6. Yeah, but for real.
    i have tried it myself i really can't get it to work....
     
  7. Using a BukkitRunnable is simple. I don't see what's going wrong with it.
     
  8. i found that to but i have no idea how this would fix my problem? it only runs a task later but it still needs to make a connection...
     
  9. No? BukkitRunnables literally have a method called runTaskAsynchronously. What are you talking about?
     
    • Agree Agree x 2
  10. If i could i would like to invite you to slap me in the face, i got it to work.... i'm gonna shoots some schools brb