[mapserver-users] Java Interface to MapServer

Andrew Collins andrewrcollins at yahoo.com
Mon Aug 19 16:22:34 EDT 2002


C F

> 1) The swig tool worked great for providing Java hooks into
> Mapscript.

I've succeeded in getting swig to produce a suitable set of Java
wrapper classes generated and compiled without serious hassle.

> 2) I was able to create functional mapscript programs in
> Java to generate maps.

I hope to be here once I get the .dll compilation process
established and automated. I'm using MingW. I am following the
approach described in "Mapserver and Mapscript/Tcl for Windows"
found in mapserver-3.6.1/mapscript/tcl/win of compiling all of
MapServer into a single mondo .dll file.

> 3) Because mapserver is not thread-safe the servlet environment
> provides prohibitive limitations. Basically what would happen
> is it (servlet) would take requests and process them fine... as
> long as you let your request finish before sending another one.

Yes, I experienced this problem with the PHP/MapScript for
MapServer 3.5 on occasion.

> As it turns out servlets hold on to the same thread for browser
> sessions which causes problems for this non-thread-safe
> environment. I've tried different ways of
> protecting/synchronizing the threads from these issues but
> without success.

True, but did you follow the strategy of having the servlet
implement SingleThreadModel?

http://java.sun.com/docs/books/tutorial/servlets/client-interaction/threads.html

> For me, the biggest scare factor is that is it seems very
> difficult or impossible to catch these errors and handle them
> gracefully. Any little disruption in the underlying mapserver
> libraries I'm accessing through JNI causes the entire JVM to
> crash! This is VERY bad. If you're in a servlet environment,
> this also causes your servlet engine to crash, so then you're
> down for good.

I agree that deep catastrophic errors related to JNI are
frustratingly difficult to debug. I would certainly prefer
to avoid this arena.

> 4) I thought about the possibility of still using Java, but
> setting it up as CGI instead of servlets. This might resolve
> the threading issues, but again, the fact that any little error
> (let's say an invalid file path or a bum layer) causes the JVM
> to crash. While subsequent requests should still work (your
> site wouldn't be down), I am still not able to handle errors
> gracefully and the fact that the JVM is crashing brings up
> scaring things like orphaned resources that build up over time
> and really screwing things up.

It seems that implementing the SingleThreadModel may solve this
problem--at least in theory.

> Since I'm developing everything else in Java, I would like to
> stick with Java, as it would solve a lot of my headaches... so
> I too would like to hear about any success stories.

I had been set on simply using PHP/MapScript, alongside all my
other Java work, for the past few months, but then I started
using JBoss 3.0 and for the sake of a stable long-term
development process I feel that revisiting a Java interface
to MapServer would be far more beneficial than being strapped
into hauling both PHP and Java into the future.

> In the meantime, I'm using a servlet to open up a URL
> connection to a local PHP/Mapscript page and returning
> the results as PHP/Mapscript works great and has excellent
> support and user base.

Yes, I agree that the PHP/MapScript work is really great.

I would like to see the same for a Java interface. :)

Thanks for your response.

My main question from this post:

Did you implement the SingleThreadModel for your servlet?

Thanks!


=====
Andrew Collins - andrewrcollins at yahoo.com
http://profiles.yahoo.com/andrewrcollins/

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com



More information about the mapserver-users mailing list