tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phillip Morelock <>
Subject Re: Improper timing using Calendar class (JSP/servlet)
Date Thu, 06 Jun 2002 05:36:40 GMT
On 6/5/02 4:37 PM, "James Williamson" <> wrote:

> George McKinney wrote:
>>> -----Original Message-----
>>> From: James Williamson []
>>> Sent: Wednesday, June 05, 2002 2:58 PM
>>> To: Tomcat Users List
>>> Subject: Re: Improper timing using Calendar class (JSP/servlet)
>>>> <%!  is seldom used and is largely discouraged except in
>>> certain situations,
>>>> perhaps like yours, although I haven't looked too closely at yours.
>>> I'm not being a troll, but who says it's largely discouraged?
>>> James
>> I'd discourage it because usually Tomcat runs its servlets in a multi
>> threaded mode (unless the SINGLE THREAD (or whatever it's really called)
>> flag is set).
>> If startTime and endTime are member variables, and no synchronization in
>> sight, I think that the various invocations of the servlet are going to
>> tromp all over each other's values. If they are local (inside the <% ... %>
>> block) that won't be a problem.
> True, but what about in circumstances where
> a) you want to share variables (obviously synchronising access to them)
> b) you want to define subroutines in your jsp files (which are thread
> safe since
> each thread gets its own stack)?
> To be frank, I was just wondering if there was a general consensus that
> using the <%!'s is not recommended.

Yes there is a general consensus, from what I can gather.  At least in every
project I have ever worked on (from my solo freelance projects to massive
projects with very senior architects), it has always worked out to do more
harm than good.

This is because:
A.  It is not necessary 9 times out of 10.
B.  It complicates source, architecture, and maintenance far more than it
solves perceived problems.

Synchronizing access to variables which are essentially locals is about the
dumbest thing you can do in Java.  Java's synchronization patterns are known
to be very slow.  Servlets and JSP's should hardly ever have anything
synchronized in them, because the environment is meant to be highly
multithreaded, and synchronization in some sense destroys that, especially
knowing how expensive Java's semaphore system is.  If you need to
synchronize a member in a JSP, you should rethink your design.

If you're actually "programming," if you need "subroutines" etc.--- you
should really be using Servlets anyway.  Servlets are for programming, JSP's
are for scripting the display output.  JSP/Servlet architecture is quite
weak when it comes to PHP/ASP/Perl style behavior and execution paths.  The
environment is designed for flexibility, robustness, and security, not speed
of development for small scale projects.  Kind of the opposite of the ASP or
PHP mentality (not that there's anything wrong with that when it's

I guess this just boils down to my 2 cents, but I still haven't heard anyone
ever tell me why they really needed this design, except to solve
nonexistent, imaginary "problems."
> James Williamson


>> George McKinney
>> --
>> To unsubscribe, e-mail:   <>
>> For additional commands, e-mail: <>
> --
> To unsubscribe, e-mail:   <>
> For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message