[mapserver-users] Mapscript/Java/Servlet users: give this a whirl...

David Graham dgraham at i3.com
Thu Jun 27 09:52:45 PDT 2002


CF,

It is a threading issue. I was woring with java and mapserver back last 
fall with pre-release 3.5. I know they have been working on the thread 
safe issues in mapserver but it does not supprise me that it has not 
gotten there yet. I have sepent a good bit of time inside the mapserver 
(maplib) code and have found numerous items that sent up red flags for 
thread safe utilization. In the end I deciced not to connect mapserver 
directly to tomcat but to simply call the mapserv CGI from tomcat. This 
was suitable for us since we did not need dynamic content on the map 
part. It may not work for you.

One thing you might want to do is to mashal threads prior to calling the 
offending subroutine. You would do it by sinchronizing on a singular 
object in the JVM. Yes this will cause a bottle neck and a lack of 
scalablility. But you should ask yourself what is your current user base 
before you worry too much about scalablility. (My experience shows that 
scalablility is over rated. Most businesses I have worked for that 
worried too much about scalablility up front, have found themselfs 
decaring bankrupsy because traffic never did ramp up! Is your product 
really going to be in that much demand?)

Here is how you would do it.

public static class MyLock {
// This class does nothing is just used to lock threads against.
}

inside your subroutine
code....
synchronize ( MyLock ) {
offending_subroutine( args );
}
more code...

Dave Graham

C F wrote:

> Thanks for your reply Herald. I wasn't aware of some of those links 
> your provided. I kind of figured it was a threading issue but I really 
> don't know much about how the threads interact once you add the Java 
> layer on top of everyhting.
> Well here's my latest... I tested this with Tomcat 4, Tomcat 3, Jetty, 
> and WebSphere... I was desparate :) I was hoping that maybe one of 
> them would be able to catch the error and display an error messages 
> instead of crashing. No Luck. They all did the same thing. I guess 
> it's just too low level (in the JVM) to recover from it.
> One other thing I did was put all my Mapscript stuff into an EJB and 
> deployed it in JBoss... and hit it from a JSP in Tomcat. This helped 
> with my initial problem... I am now able to hit refresh as fast as I 
> want! HOWEVER, now if I hit it from different browsers at the same 
> time.... it crashes JBoss (not Tomcat).
> I then recompiled Mapserver/Mapscript with the "--with-threads" option 
> and tried it again. Now I can't even get it to work AT ALL... 
> "Exception occurred:edu/umn/gis/mapscript/mapObj"
>
> Unless I can play around with thread management in JBoss, I'm about 
> ready to give up too. What other options are there? I gave up on PHP 
> Mapscript because of some of the limitations there... now I've spent a 
> week on Java. What else is there? Maybe I should writing the group and 
> asking about Perl issues/limitations before trying that...
>
>
>> From: "Harald Wehr" <hwehr at hs-harz.de>
>> To: mapserver-users at lists.gis.umn.edu
>> Subject: Re: [mapserver-users] Mapscript/Java/Servlet users: give 
>> this a whirl...
>> Date: Thu, 27 Jun 2002 07:58:43 +0200
>>
>> Hi CF,
>>
>> I faced the same problems some times ago and never found a solution to
>> this problem.
>>
>> See these mails i wrote to this list.
>>
>> http://mapserver.gis.umn.edu/wilma/mapserver-users/0203/msg00298.html
>> http://mapserver.gis.umn.edu/wilma/mapserver-users/0204/msg00137.html
>> http://mapserver.gis.umn.edu/wilma/mapserver-users/0203/msg00373.html
>>
>>> I've been having this very unusual problem running servlets and
>>> mapscript. As far as I can tell, it's working great except under one
>>> condition. If a user submits a request to the servlet, then hits the
>>> browser's refresh button before the his/her previous one is 
>>> finished, it
>>> *crashes* my servlet engine. This only happens if I'm executing
>>> imageObj.draw() somewhere in it *and* trying to print a response 
>>> back to
>>> the client. If I don't do anything with my HTTPServletResponse object,
>>> I can hit refresh as many times as I want as fast as I want with no
>>> problems. Anyway, without getting too deep into the issue, etc. I would
>>> be grateful if someone else could try doing this.
>>
>>
>> It is really curios to find the responsible fault. Sometimes it worked
>> several times, some times the sevlet container crashes.
>>
>>>
>>> Submit a request to your servlet that draws a map and saves out to an
>>> image (one that takes at few seconds or more).
>>> Then hold your <CTRL> key down (to make sure it refreshes) and hit your
>>> refresh button a few times fast while your first request is still 
>>> pending.
>>> Sometimes it'll keep showing you the cached page after the servlet
>>> engine has crashed. So after that, try moving to another page being
>>> served by your servlet engine, or change your url params or just 
>>> somehow
>>> check to make sure it actually *is* running.
>>
>>
>> It seems to be a threading issue. Look at one of the above postings.
>>
>>>
>>> I'd like to hear your results.
>>>
>>> Here's my environment.....
>>> Linux 7.3
>>> Tomcat 4 (standalone)
>>> JDK 1.4 (J2SDK)
>>> --------------
>>> MapServer version 3.6.0 OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP 
>>> SUPPORTS=PROJ
>>> SUPPORTS=TTF SUPPORTS=WMS_SERVER INPUT=TIFF INPUT=EPPL7 INPUT=JPEG
>>> INPUT=POSTGIS INPUT=SHAPEFILE
>>> ---------------
>>> My data is all in PostGIS
>>
>>
>> I have nearly the same environment.
>>
>> Harald
>>
>>
>>
>
>
> _________________________________________________________________
> Join the world's largest e-mail service with MSN Hotmail. 
> http://www.hotmail.com
>
>
>


-- 
David W. Graham
Director of Geospatial Applications Development
information integration and imaging, LLC
201 Linden St, Third Floor
Fort Collins, CO 80524
(970) 482-4400
dgraham at i3.com
http://www.i3.com






More information about the MapServer-users mailing list