The Need for java.lang.Thread and java.sql is Gone

At least for the application developer.

Back in the days of Java1, two cool parts of this new platform was the threading apis and the JDBC apis. These APIs have both had immense success. But I think we, as application developers, should forget about them. I know I mostly have.

There are good reasons, that these apis were cool and became popular and much used.

The JDBC apis were a giant leap in how easy, it suddenly was to connect to and query a relational database. And with the common JDBC api, you could just swap the driver and connect to another database. With the threading apis this was even more true. Coming from C, parallel programming was done with multiple processes and various IPC techniques like sockets or shared memory. Suddenly, there was an easy to use api, with Thread as abstraction level.

Before the success of application servers like Weblogic and Tomcat, back in the days where Weblogic was named Tengah, we all wrote our own server applications, using stuff like Thread pools and dispatching work into threads by ourselves.

But this is no more. When reading Effective Java (again), I came across all the advice on how to do parallel programming. And I came to think of, that it has been a really long time, since I used the threading apis myself directly. And the same is true for the JDBC apis. I know intimately how they work, and I am glad for that, but I don’t like working with them anymore. They are a way too low abstraction level.

Doing applications on the web, the container shall be the one using those apis. Not the application developer. Doing application development, we should use higher abstractions like JPA, to enable better modelling and talking in the language of the model when coding.

What do you think? Is there any need for application developers to use these libraries anymore, except for rarely written software?

August 28, 2008  Tags: , ,   Posted in: Design, Programming

14 Responses

  1. Ben Hill - August 28, 2008

    I work for a enterprise product company and we use threading frequently and sql often. Threading is required for scalability. SQL to interface with third party products and customer databases.

    This packages are far from dead in my part of the coding world.

  2. Steven - August 29, 2008

    i agree with ben.
    i frequently use threads and jdbc directly.

  3. bob - August 29, 2008

    you are fucking crazy

  4. Ash - August 29, 2008

    What about the developers who are writing “tomcat” type server software?

    - http://www.indiabolbol.com

  5. henk - August 29, 2008

    I agree with the author. The average programmer doesn’t use those low-level constructs as often. In some parts of Java, you really shouldn’t use those anyway (like EJB for example). There are plenty of high level replacements out there or just on the horizon.

    The low level SQL stuff will be mainly replaced by JPA. Yes, I’ve already seen a bunch of people starting with Java and going straight to JPA. They never even touched the JDBC APIs.

    I suspect a similar thing will be happening to Thread. With all the goodies already available in the Java 5 concurrency package and more on their way for Java 7, I see the need to manage your own Thread classes *greatly* diminishing. In fact, very soon it might even become an anti-practice. When we all work with 32+ core CPUs, no way that Joe-average Java programmer is going to manage that efficiently.

  6. henk - August 29, 2008

    @Ash
    “What about the developers who are writing “tomcat” type server software?”

    Does people will probably continue using Thread, although even they want to take advantage of higher level constructs and let the low level nitty-gritty to the JDK. Just read through some of Jboss’ commit comments.

    Then again, how many teams in the world are writing “tomcat” type server software? I would be very surprised if it where more than a 1000. Frankly I think it’s not even more than 10. This will mean low level Thread is for a very specialized use, while ‘the rest of us’ will move on to higher level constructs.

  7. Chris - August 29, 2008

    We use java.lang.Thread heavily throughout a huge portion of our codebase. We also use plently of the newer concurrency APIs where suitable. But they aren’t (yet) anywhere near a complete replacement for java.lang.Thread and it’s very unlikely they will be for a long while yet.

    As for JDBC, that’s all we use everywhere for all our DB code. JPA doesn’t even come close to meeting our performance/scalability/functionality requirements for the most part (very high volumes, data warehousing). We could theoretically use JPA when talking to some of our admin/config databases, but adding a mix of technologies (JPA + JDBC) and a further layer of abstraction to existing code with only debatable benefits (for us) doesn’t appear to be a very sensible move.

    Note that we primarily write server software (on pure J2SE) that involves shunting around terabytes of data and number-crunching on 8-32 core CPUs that are distributed globally, so we’re probably not your typical Java dev environment. But we also have Swing GUI tools and to a lesser extent some webapps. And I have to totally disagree with Henk’s estimates, there are more than 10 of us here alone writing software of that nature. Just because it’s in-house and proprietary doesn’t mean we don’t face the same challenges as a much higher visibility project like Tomcat.

  8. raveman - August 29, 2008

    great point with this article. I know that companies that are still using JDBC do exist, but its just laziness on their part.

    Why learn new API when you are using JDBC for 10 years and are happy with it?

    First reason should be developers, i dont think you will find many people that want to maintaine that code. Plus do they always close connections and do all the other closing?

    Spring + JdbcTemplate is always better than pure jdbc.

  9. henk - August 29, 2008

    @Chris

    As you mention, you are obviously not in a typical Java dev environment ;) You are right perhaps that the “no more than 10″ estimate was exaggerated, but I really would be surprised if it was more than a 1000 teams writing such software. The overwhelming majority of Java programmers seems to be writing the kind of software where JPA actually is the better solution.

    Of course “better” is a term open to debate, but I simply see it happening in practice. I’ve seen batches of Java programmers who didn’t start out with JDBC but based their very first applications that used persistence on the JPA or Hibernate API.

    Now this may be sour to us. We -know- that JDBC is more powerful and has better performance. On the other hand, in 1989 I also knew assembly had better performance. Yet all those crazy youngsters around me started coding in C/C++. In 1997 I knew C++ gave me more power and more performance, but yet those crazy youngsters again started programming in Java.

    I’ve been around in IT since approximately 1983. Perhaps not as long as some other veterans, but I think it’s still some time. After a while you simply see certain patterns reoccurring.

    A minority group will keep using the powerful tools of yesterday. Even to this day, people still program assembly language. It’s just that you wouldn’t code your entire average enterprise system with it these days, but restrict its usage to small pieces of ultra high performance code, some drivers and some embedded stuff. I really think the same will happen with Thread and java.sql. Maybe not today, but surely tomorrow.

  10. Caligula - August 31, 2008

    > Frankly I think it’s not even more than 10.

    So… Tomcat, Resin, jBoss, WebSphere, WebLogic, Jetty, GlassFish, Enhydra, Geronimo, and OC4J each has a single developer?

    I find that unlikely.

  11. Cliff - September 2, 2008

    (Thread || JDBC).equals(”boilerplate logic”)

    While saying Thread and JDBC is dead may send a confusing or misleading message the author makes a very valid point. For modern software there are plenty of high level replacements for these APIs. I frequently find myself tucking calls to these types of APIs behind interfaces to be either immediately or eventually replaced by a framework like Spring, EJB, iBatis, or the like. There are a few other APIs I would rank similarly such as URL. The problem with URL is that people still think they actually need it in high level interfaces. Most often what you need/want is a callback such as:
    Object result = requestData(String requestQuery,
    new MyCallBack(){
    public Object recieveData() { /*…*/ }
    }
    );
    Using these lower level APIs puts these APIs as a direct dependency of the code you write. It’s limiting and unnecessary unless you yourself are writing a framework.

  12. henk - September 3, 2008

    Here’s another article signaling the same trend: http://www.simonsegal.net/blog/2008/09/01/will-orm-mass-adoption-kill-sql-skills/

    @Caligula

    Read what I initially wrote: “teams” not individuals. Also, I already mentioned that 10 may indeed be an underestimate.

  13. werutzb - September 29, 2008

    Hi!

    I want to extend my SQL knowledge.
    I red really many SQL resources and still feel, that I am not an expert
    in SQL. What can you recommend?

    Thanks,
    Werutz

  14. polesen - September 29, 2008

    @werutzb: Sorry. No big recommendations from me.