Perhaps the best hardware configuration for a server running VisAD in
servlets would include a high-performance graphics card for doing the
rendering, just with no monitor plugged into it. Obviously, performance
would be significantly enhanced when compared to doing the rendering on
the CPU, and the performance increase probably more than justifies the cost.
Other than the _visibility_ of the rendering - i.e. to anyone watching a
monitor pluged into the server, there's every reason to use a graphics
card to ease the burden on the server's CPU.
I don't know enough about graphics cards to know if you can render on
their hardware without sending the output to the monitor, but it might
be that pursuing offscreen rendering might be to some extent shooting
yourself in the foot for performance reasons.
Sorry if this has already been discussed / discounted! It just suddenly
occurred to me...
Valliappa Lakshmanan wrote:
A quick update for any one else who may find themselves in the
same boat ... A poster on the Java3D list indicated that Java3D
does not work in the headless mode (my hack below produced
a GraphicsConfiguraiton that led to a ClassCastException deeper
down inside Java3D).
So, can you use VisAD from within servlets? Yes, but in a more
round-about way. This is what I did:
1) I created a Java application that had a visible JFrame. The
server dynamically creates images and writes them out to the
2) The servlet opens up a socket connection to the application,
and passes on the request. The app creates the image, writes it
out, and notifies the servlet via the same socket.
3) The servlet returns an image tag back to the client.
This works, but as would be expected with off-screen rendering,
it is quite slow.
Valliappa Lakshmanan wrote:
Here's a hack that works -- read an image, and use the
Graphics2D from that Image to get a GraphicsConfiguration.
Perhaps, you can change one of the APIs to accept
such a graphics configuration from the application,
since you probably don't want the VisAD classes reading local
Thanks for your help.
// run as: java -Djava.awt.headless=true OffscreenImage
public static void main(String args) throws Exception
BufferedImage template = ImageIO.read( new File("test.jpg") );
Graphics2D g = template.createGraphics();
GraphicsConfiguration config = g.getDeviceConfiguration();
if ( config != null )
System.out.println( "Got valid GraphicsConfiguration" );
Bill Hibbard wrote:
On Fri, 27 Aug 2004, Valliappa Lakshmanan wrote:
Thanks, Ugo. I was not aware that you could specify a headless
environment that way.
I think this is the right way to go, because ultimately, I want to
using VisAD within a servlet, and servlets are headless.
I added -Djava.awt.headless=true to the invocation of the java VM
when I ran my test program.
I now get a InitializerException thrown from
VisADConfig.makeConfig calls getDefaultScreenDevice() which throws
I'm thinking that:
(a) if I'm creating an offscreen DisplayImplJ3D, it should not be
asking for a default screen device.
or (b) DisplayImplJ3D.initialize() should gracefully handle a
Good idea. However, the VisADCanvasJ3D constructor needs a
non-null GraphicsConfiguration to pass as an argument to
the super() constructor for its parent Canvas3D class. I
took a quick look at the GraphicsConfiguration, GraphicsDevice
and GraphicsEnvironment JavaDocs but couldn't see an obvious
way to construct a GraphicsConfiguration without a GraphicsDevice.
If you or someone else can suggest a way, we can catch the
java.awt.HeadlessException in VisADCanvasJ3D.makeConfig() and
use your alternative. There is hopefully an easy way to do this
that my quick look missed.