-2

I want to use an object pool for managing SMTP server connections, since they are very expensive to create (takes half of the total time of sending an email). So far I found the only options to be:

  1. Use Apache Commons Pool or some other 3rd party library
  2. Write it myself (risky!)

Doesn't the JDK provide an object pool? I rather not depend on a 3rd party and this seems like a pretty generic/basic feature to me.

Benny Bottema
  • 11,111
  • 10
  • 71
  • 96

1 Answers1

1

Doesn't the JDK provide an object pool?

As of Java 11, the Java SE libraries do not provide a general purpose object pool.

But if you look around, you will probably find a range of 3rd party libraries which do.


I rather not depend on a 3rd party.

In the words of the Rolling Stones song:

"No, you can't always get what you want ...."

But seriously, the Sun / Oracle Java developers never saw as it as Java SE's role to provide all of the libraries you could possibly ever need. If you exclude 3rd party dependencies from your products, then you will end up writing and maintaining a lot more code than is necessary.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thank you for the answer, but that last paragraph is rather unnecessary. There are many valid reasons why a 3rd party dependency can be undesirable. Moreover, I'm looking for something generic, a basic object pool. By your reasoning, the Collections API, ExecutorService framework and a billion things shouldn't be in the JDK. – Benny Bottema May 30 '19 at 10:00
  • Yes. There are valid reasons to avoid using certain types of library. But I find it hard to understand why you would want to avoid *all* 3rd party libraries. And it is not my reasoning. This is what the Java SE designers themselves say. (Can't find quotes.) The ever-growing size of the Java SE libraries (in a JRE) was a cause of complaints from lots of people concerned with the size / speed of installer downloads. – Stephen C May 30 '19 at 10:15
  • Anyway, if you are using jlink, it should make little difference (to downloadable size) whether a class is in the Java SE libraries or a 3rd party libraries. The jlinked executable will only include the required modules from either source. (There ain't a JRE anymore!) – Stephen C May 30 '19 at 10:20