Lenniey
Lenniey

Reputation: 103

JAX-RS RESTful Service and permanent Oracle connection

I am writing a RESTful service which consumes application/octet-stream and accepts binary files to write them to disk (Tomcat 8, Windows Server 2012R2, JAX-RS). I then need to insert the file contents into an Oracle table.

The service itself runs fine, accepts files and writes them to disk. My problem (or call it best-practice question) is, how to transfer the data to the Oracle DB. Of course I can open a connection in the service itsef which gets called everytime the service accepts a file, but is this really the "correct" way? We're talking about MANY small files (let's say 100 per minute, each about 300 byte in size).

Should I create a connection pool? Or even a standalone program which keeps the Oracle connection open permanently? Unfortunately, I can't really benchmark at the moment because I am on an isolated test server.

So, tl;dr: How to transfer the content of many small files accepted by a RESTful service to an Oracle DB?

Upvotes: 0

Views: 179

Answers (2)

Johannes Jander
Johannes Jander

Reputation: 5020

As you are deploying on Tomcat, using the Tomcat managed connection pool is the most generic way. We use this and get very good performance out of it. You could roll your own and benchmark it, but I am not sure about the merits of this. I know I would try the way that's best integrated with Tomcat first and only if it does not perform move to libs like C3P0.

Depending on your use-case you could do without writing the files to disk and instead just insert them into the DB. Since your files are small, there would not even be a reason to go async or fork threads for insertion.

Upvotes: 1

sisyphus
sisyphus

Reputation: 6392

Connection pools are the most generic way to go here. There's lots of reasons - separating the concerns of connection management from connection use, scalability control through configuration, overcoming the latency associated with connection setup,...

There's lots of implementations of simple connection pools out there, they can be found in application servers or libraries - c3p0 is a nice and easy one for a standalone, self-contained webapp.

Upvotes: 0

Related Questions