So I recently started using Netty for my applications client/server communication and I discovered I loved the idea of listenable Futures. I wondered why I didn't know about Java being able to do this, and, sure enough, it cannot.

After some searching I realized that this is a feature provided by Guava's concurrency tools, which got me skimming through it's user guide. It seems awesome, but I have some concerns:

  1. I already have a decent amount of code that uses JDK concurrency. How hard will it be to migrate over?
  2. What is the risk of starting to become a "Guava programmer" so to speak? How difficult will it be to bounce back and forth between doing things the Guava way and the core Java way?
    • What potential harm could there be if, in an existing project, I write new classes with Guava classes without migrating the rest of the code over?
  3. Is there a good guide for slowly beginning to use Guava features without having to stop doing my actual job to train myself for a few days/weeks?
  4. Is there anything else I should know in advance that I haven't already thought of?

I think the underlying issue you have is that you're thinking of Guava as if it's an entire framework or DSL (domain-specific language). Guava is another library like Apache Commons where it provides common abstractions, data structures and convenience methods complementary to the JDK libraries.

Answers to your questions:

  1. If your code is designed well, it shouldn't be difficult to use Guava's concurrency library.
  2. No risk of being a "Guava programmer", as I mentioned, Guava is not a DSL or JVM language (like Scala/Groovy) where you will dramatically write code differently.
  3. Besides the Wiki, JavaDocs and PDFs you find on the site, you will find plenty of blog posts on using Guava. I don't know of any books or publications that are otherwise available. It should not take you more than a few days.
  4. No.

The only exception I see to the above is that you want to use Guava's Functional idioms and use it as an introduction to Functional Programming in Java. Then I could see a paradigm shift occurring where you will write code differently. In that case:

  1. There is a book called "Functional Programming in Java" by Dean Wampler that talks about FP pre-Java-8. There is a beta book published by PragProg that talks about FP using Java 8 features.
  2. The Guava wiki itself warns you to use Functional idioms judiciously:

    Excessive use of Guava's functional programming idioms can lead to verbose, confusing, unreadable, and inefficient code. These are by far the most easily (and most commonly) abused parts of Guava, and when you go to preposterous lengths to make your code "a one-liner," the Guava team weeps.

You will find from reading the above that FP (pre Java-8) can be very awkward and verbose (due to lack of first-class functions and having to use inner classes). Believe me, there is some code in our codebase that (ab)uses these idioms and the team complains about it all the time (how it is hard to read and understand), despite having no aversion to FP in general.

  • You don't have to worry about me programming in Java like it's OCAML. I left that language in the dust long ago in undergrad :) – durron597 Apr 23 '13 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.