简体   繁体   English

JAX-RS RESTful服务和永久的Oracle连接

[英]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). 我正在编写一个RESTful服务,该服务使用application/octet-stream并接受二进制文件以将它们写入磁盘(Tomcat 8,Windows Server 2012R2,JAX-RS)。 I then need to insert the file contents into an Oracle table. 然后,我需要将文件内容插入Oracle表中。

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. 我的问题(或称其为最佳实践问题)是如何将数据传输到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? 当然,我可以在服务itef中打开一个连接,每次服务接受文件时都会调用该连接,但这真的是“正确”的方法吗? We're talking about MANY small files (let's say 100 per minute, each about 300 byte in size). 我们正在谈论许多小文件(假设每分钟100个,每个文件大小约为300字节)。

Should I create a connection pool? 我应该创建一个连接池吗? Or even a standalone program which keeps the Oracle connection open permanently? 甚至是一个独立的程序,它可以使Oracle连接永久打开? 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? tl; dr:如何将RESTful服务接受的许多小文件的内容传输到Oracle DB?

As you are deploying on Tomcat, using the Tomcat managed connection pool is the most generic way. 在Tomcat上进行部署时,使用Tomcat托管连接池是最通用的方法。 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. 我知道我会先尝试与Tomcat最佳集成的方式,并且前提是它不能执行向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. 由于文件很小,因此甚至没有理由去异步或派生线程进行插入。

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. 简单连接池的实现很多,可以在应用程序服务器或库中找到它们-c3p0对于独立的自包含Webapp来说是一个很好的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM