Skip to main content

Reinventing the Wheel to Run Myself Over

Posted by editor on October 23, 2008 at 11:07 AM EDT

Getting thread pools right... really right

Have you ever noticed that a lot of people who present the idea of pools in the abstract -- whether for database connections, threads, whatever -- seem to implicitly assume that the demand for the pooled resource will never exceed the number of available resources? In other words, the first time someone explains this to you, they show you why it works when two or three database connections are needed at the same time, but they're not as eager to think through what happens when all 50 connections are in use, and request number 51 comes in.

What do you do when this happens? Do you throw a "try again later" kind of exception? Do you block the caller (and blithely assume the caller can stand being blocked without ill effect on the rest of the system)? Do you work out some means of letting the caller decide what to do?

In our Feature Article, Amir Kirsh takes on this problem for thread pools in Creating a NotifyingBlockingThreadPoolExecutor:

Recently, my colleague Yaneeve Shekel had the need for a thread pool that would work on several tasks in parallel but would wait to add new tasks until a free thread was there to handle them. This is really not something bizarre: in fact, this need is quite common. Yaneeve needed it to analyze a huge directory with a very long list of files, where there was no point in piling on more and more FileAnalyzeTask instances without a free thread to handle them. The analyze operation takes some time, while the speed in which we can pile files for analysis is much higher. Thus, not controlling for thread availability for the task would create a huge queue with a possible memory problem, and for no benefit.

Concluding that what he needs is a ThreadPoolExecutor that blocks when the queue is full, he finds that Java does not provide this functionality out of the box, and the simplistic means of performing it aren't as straightforward as you might think. Acknowledging one implementation provided by Brian Goetz in a forum reply and again in his book Java Concurrency in Practice, Amir shows off a different approach and the thinking behind it.


In Java Today, the NetBeans IDE 6.5 Release Candidate is now available for download. New features in 6.5 include PHP support, improved JavaScript support, more database features (SQL history, SQL completion, results viewing, and editing improvements), support for Nimbus in the GUI builder, single test method support for JUnit, and a redesign of the debugger's Step Into features. It also integrates with new versions of key technologies, like GlassFish Enterprise Server v3 Prelude. Also, check out the features from the first two days of the NetBeans 10th Birthday Celebration.

In an article adapted from a presentation at Sun Tech Days in Sydney, Chuk-Munn Lee of Sun Microsystems Troubleshoots Java SE 6 Deployment. The article explores ways to troubleshoot running Java applications, with a focus on Java SE 6, covering memory management, command-line and visual tools, common problems and their causes, and more.

Sun is sponsoring a contest for independent developers and students working with Project Darkstar, the Java-based MMO gaming back-end engine. The Project Darkstar Developer Challenge is looking for the best applications and utilities for Project Darkstar and offers some enticing awards. Grand prize winners get a 2009 Game Developer Conference (GDC) pass and an opportunity to show their work in a GDC presentation, plus cash for travel and a feature on the Project Darkstar site. Entrants must be members of the Project Darkstar community, and must submit their entries between November 17, 2008 and January 19, 2009.


In today's Weblogs, John Ferguson Smart considers approaches for Software development in troubled times. "Nowadays, more than ever, developers need to be productive. Ultra-productive. Organizations need to optimize the added value they get out of their development projects, and should be actively looking for ways to do it."

In Enabling performance feature in jMaki, Carla Mott writes that "jMaki 1.8.0 release contains performance enhancements which help improve page load times."

Finally, in ASM and invokedynamic, Rémi Forax discusses how "ASM now supports the new invokedynamic opcode."


In today's Forums, Qunhuan Mei hopes for LWUIT guidance in the thread RE: Roadmap "Hello LWUIT team, would also like to echo this request. "Roadmap" would be very important for anyone who are seriously consider using LWUIT for commercial work. Currently we know it works pretty good on J2ME. It works as it is for Blackberry. Will the LWUIT be able to work in any other platform, or is it true the LWUIT will not work on Android ...? Would anyone from LWUIT shed some light on this please?"

quintesse is having GlassFish Update Center problems in Proxy user/password setting for Update Center V3 prelude. "There was another thread about this (posted by somebody else) but a (working) answer was never given. Does anyone know how to configure a username/password for the glassfish v3 prelude (b28) update tool? If I try to run the update tool from [glassfish-install]\bin\updatetool.bat it detects it isn't installed yet and tries to download itself (at least that's what I think it tries to do), but it fails with a HTTP 407 error "Proxy authentication required"."

davood wants to go DLL-free with a portable java 3d solution. "I'm working on project which needs some 3d effects and it's in java. The problem I have is that I need to create a single pure java based solution targeting java 5. Java3d seems to need dll files for windows and so on for other platforms. I know this is for hardware acceleration and performance but my performance needs are not high and more important thing is portability. I can't ship different version for windows, linux, mac, .. So is it possible to use java3d without its native libraries (without hardware acceleration or something) or is there any other library for java letting me to create good looking scenes in 3d in pure java?"

Finally, kirillcool offers a thumbs-up to SwingX's use of renderers in Re: [FYI] Overhaul of BasicMonthViewUI painting code. "I rather like the new renderer-based approach. It is not without minor flaws (see below), but results in cleaner and smaller code than before for the third-party LAFs. The latest 5.1dev drop of Substance SwingX is using build 1283 of SwingX (from today) and was migrated to the new API. Here is what i had to do, along with the comments on possible changes in the basic delegate to accomodate third-party LAFs:"


Current and upcoming Java Events :

Registered users can submit event listings for the java.net Events Page using our events submission form. All submissions go through an editorial review before being posted to the site.


Archives and Subscriptions: This blog is delivered weekdays as the Java Today RSS feed. Also, once this page is no longer featured as the front page of java.net it will be archived along with other past issues in the java.net Archive.



Getting thread pools right... really right