Adding HikariCP to plugin

Discussion in 'Spigot Plugin Development' started by Random_Cow, May 28, 2016.

  1. Hello, does anyone know of any good tutorials on adding HikariCP to your plugin. Preferably a detailed guide to maven and the steps required to successfully build HikariCP into the plugin. I haven't been able to find much info on adding HikariCP as a dependency, just found a whole bunch of guides on how to use it in your plugin.

    Current pom.xml file: http://hastebin.com/emotazujos.xml
    Outputs nothing but the contents of the /src/... class files. Its relatively smaller than the one exported on eclipse, about half the original size.
    Build method: through eclipse pom file > mvn install | also tried mvn clean install on git
     
  2. You need to look into the maven shade plugin if you want to bundle HikariCP with your plugin. The shade plugin includes the dependency with your plugin, so the user doesn't have to download another jar.

    Also, please make sure that the license for the jar you're shading allows for redistribution.
     
  3. Whereabouts do I run this shade plugin. In eclipse or in Windows git?
     
  4. The shade plugin is entered into your pom.xml, you configure it there too.
     
  5. Look over my source: https://github.com/bob7l/HawkReloaded/blob/master/pom.xml#L92

    Annd the using it...
    https://github.com/bob7l/HawkReload...i/HawkEye/database/ConnectionManager.java#L20
     
  6. Does HikariCP have some sort of cache, since I saw in your code there was something to set cache limits. If there is a cache, how would one go about using it. I'm assuming that HikariCP doesn't run off the async thread as well and that you must make a bukkitrunnable for it.
    Code (Text):
            config.addDataSourceProperty("rewriteBatchedStatements", "true");
            config.addDataSourceProperty("prepStmtCacheSize", "275");
            config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
            config.addDataSourceProperty("cachePrepStmts", "true");
     
  7. No those are MySQL/jdbc "optimizations" recommended by the HikariCP developers. I'd only use them if you're planning on doing massive inserts like we do with HawkEye.

    And HikariCP is just a connection pool library. It doesn't replace Java's JDBC and doesn't really speed anything up unless you're doing A LOT of random queries from different threads. Think of it as a means of getting JDBC connections and nothing more.

    Annnd you still have to perform your queries on another thread (Unless you don't care about slowing down the main thread lol). I wouldn't personally use BukkitRunnables unless you're using them for the timings. The one good thing about bukkit's Async timers is the fact they don't spam threads, but rather use a fixed thread pool. I'd still recommend you make your own thread/thread-pool to execute the queries.
     
  8. Would you be able to give me an example or link me to a guide to create thread-pools. Why wouldn't you recommend bukkit's async timers for anything other than timings btw.
     
  9. https://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html

    You could also very easily design your own thread pool using a lockedQueue paired with a producer -> consumer implementation. Having a thread pool simply provides instant access to threads and prevents all the overhead associated with constantly creating new threads.

    Because Bukkit's async timers are... Timers. I don't see any reason why you'd want to delay your query for a tick just to use bukkit's internal thread pool. I personally just like to have complete control over my threads/execution aswell.