Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Connection Pooling

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been getting some errors on my program relating to running out of sockets. In searching for a solution to this I have seen Connection Pooling as a likely solution. It also promises performance benefits and greater control over the DB usage. I'm keen to give it a go. All of the examples I could find relating to this used Eclipse, Maven or some commercial driver. I don't use any of these, I write my programs in Netbeans and that keeps things simple.

I found this site: https://docs.oracle.com/database/121/JJUCP/manage.htm#JJUCP8180 and put together the code below. It compiles but when I run it I get the error at the bottom. Can anyone tell me where I can find a simple example of connection pooling not using Eclipse, Maven or anything else? Alternatively what did I miss in my code and how do I then use this DataPool when it is working?


run:
Exception in thread "main" java.lang.NoClassDefFoundError: oracle/jdbc/OracleShardingKeyBuilder
at oracle.ucp.jdbc.PoolDataSourceFactory.getPoolDataSource(PoolDataSourceFactory.java:48)
at datapool.DataPool.main(DataPool.java:31)
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.OracleShardingKeyBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
C:\Users\NeilB\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
 
Bartender
Posts: 1259
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a ConnectionPool is undoubtedly good idea, but not for the reasons you're talking about. If you run in a socket exhaustion, most likely you have severe connection leaks here or there in your code, and using a pool won't help.
A connection pool, indeed, should be used to save opening phisical connection time. If there are connection leaks, you'll  run out of available connections in the pool.
So, first check if in your code there are no leaks.
This said, I don't understand the requirement about not to use Eclipse or Maven. I guess you need a simple jar you need to add to your project's classpath, without using Maven.
If that's true, try with Hikary connection pool - just google for it, and you'll find a lot of examples.
Last, but not least, please remember that "general" connection pool libraries work together with specific DBMS driver. In your example, looks like you're trying to use UniversalConnectionPoolManager  with MySql driver.
UniversalConnectionPoolManager seems to be the specific datasource implementation for Oracle DBMS, not a generic wrapper like Hikary.
My humble advice: have a look at some examples on the web (hikary + mysql), grab the underlaying concepts, and then go further.
 
Neil Barton
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Claude, I had been looking at c3p0 but haven't got very far as all the examples are in Maven. I'll have a look at Hikary, I'd seen it around but had favoured c3p0 by chance.
 
Neil Barton
Ranch Hand
Posts: 50
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Again Claude,
I found some code using the hikari library and got it working. Whilst implementing it I tidied up the DB access code and closed the leakage which became fairly obvious! The code now runs about 3 times as fast and that's before I try different numbers of connections to optimise it. Excellent, thanks!
 
Claude Moore
Bartender
Posts: 1259
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Neil Barton wrote:Thanks Again Claude,
I found some code using the hikari library and got it working. Whilst implementing it I tidied up the DB access code and closed the leakage which became fairly obvious! The code now runs about 3 times as fast and that's before I try different numbers of connections to optimise it. Excellent, thanks!


Glad it helped !
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic