Skip to main content

Merry Go Round

Posted by editor on February 11, 2008 at 8:11 AM PST


Silly ways to burn CPU cycles

I wasn't sure if I could put Greg Colvin's latest Artima column, How To Go Slow, on the java.net front page today, because his examples of bad programming are in C++ and its overall relevance to Java is perhaps more by analogy than anything else.

But still, even if you rarely or never use C++ (like me), I'll bet you can see that

   loop:
      if (!data_available)
         goto loop;
      get_data();

sucks, and

   loop:
      if (!data_available) {
         sleep(timeout);
         goto loop;
      }
      get_data();

sucks somewhat less. I imagine many of you did a mental port of those examples to:

    while (! dataAvailable()) {}
    getData();
</pre>
   
and

<pre>
<code>    while (! dataAvailable()) {
        Thread.sleep(timeout);
    }
    getData();
</pre>

<p>
Granted, you might have hard-coded your favorite value for <code>Thread.sleep()
, or just used Thread.yield() instead. Or heck, maybe you thought of ditching the polling altogether and making your code just Object.wait() here for a Object.notify() to be called from dataAvailable(). Or maybe you thought of a nice, clean use of java.util.concurrent.

Whatever the case, Greg makes great points about how fairly simple code can have ruinous effects on performance. Some of the topics he points out aren't obviously bad at first, but depend on implementation details. His "thrashing" example shows the performance differences of working through a two-dimensional array by column or by row -- due to the arrangement of the rows in memory, proceeding by row often means the next cell you need is typically in the pipeline, cache, etc., just before you need it. The column-oriented version of the code isn't obviously bad, but it ends up being far less performant in real life. Aside: it would be interesting to know if Java behaves the same way. His example of "hanging" is also a textbook case of deadlock... just replace the acquire calls with Java synchronized statements.

If you don't mind doing some mental ports to Java, there's a lot to enjoy in his column. It's well worth remembering how the little things add up after you do them a few million times.


In Java Today, the Rio project has announced Rio 3.3 M1, the first official update for the Rio project in quite some time. "Rio is an open source technology that provides a dynamic architecture for developing, deploying and managing distributed systems. Rio provides QoS based management for distributed systems, providing a policy based approach for fault detection and recovery, scalability and dynamic deployment." New features include dynamic proxies for associations, a smart proxy framework, better POJO support, a new UI, a new command-line interface with an interactive shell, updated documentaiton, and many bug fixes and improvements.

Interested in JDK 6 Update N, also known as the "consumer JRE", but want to find out more? A Java SE 6 Update N Early Access FAQ document provides general and installation information, a description of the Java Kernel, the new plug-in, and more.

The latest edition, issue 157, of the JavaTools Community Newsletter is out, with tool-related news from around the web, a brief comment on JavaOne session proposals, new projects in the community, and a Tool Tip on using JFeature for tracking your software requirements.


In today's Weblogs, John Reynolds makes the case for BPM tools in Drive the Path (process and data flow). "Any tools can be used wrong, and I believe that's the reason many developers hate BPM. They just don't know how the BPM tools should be used... and I'd love to rectify that situation."

In Flamingo component suite 3.0 - ribbon, Kirill Grouchnikov shows off "the latest visuals of the Swing ribbon component from Flamingo component suite."

Finally, Arun Gupta announces GlassFish v3 Ruby Gem - New Home on RubyForge. "GlassFish v3 Gem allows JRuby-on-Rails application to be launched in GlassFish v3 server. It provides a robust alternative to WEBrick and Mongrel for development and deployment of your JRuby-on-Rails applications."


In today's Forums, Clive Brettingham-Moore explains JAXB handling in Re: LogicalHandlers and augmented JAXB Contexts. "Your jaxb cross context problems are because you are handing JAXB beans to a context that doesn't understand them - if you marshal the objects into DOM elements first, then include them in the any content list it will work fine. On unmarshalling alien elements will appear as DOM Elements which can be used directly or unmarshalled using a suitable context."

iceandfire wonders How is Exception logging supposed to work? "I have two stateless session beans A and B, B is injected into A. If B throws an exception it automatically appears in the server.log as INFO. I catch the exception in A and log it as SEVERE, so every exception is logged several times, one with the correct log level and one with a wrong log level. The multiple logging of exception makes the server log very hard to read. How is this supposed to be configured / coded to have useful logging files."

Finally, iwaters would like guidance to Move from .Net to Java. "I have been an ASP/.Net Web Developer for around seven years. I am interested in expanding my toolset considerably by learning Java and Oracle, but I have no-idea where to start. Aside from leaning the actual Java language what other things should I be looking at? For example would learning JBoss or Oracle App Server be more benefical? Is there much point learning about Swing if I am going to remain developing web applications, or should I do both? What IDEs should I be gettting used to, NetBeans or JDeveloper?"


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.



Silly ways to burn CPU cycles