Hi,
To which clas belongs your createReport() method ?
To be sure you can synchronize on a session-level lock object:
Add the following getLock method to one of your servlet class:
public static Object getLock(HttpSession ses, String lockName) {
Object myLock = ses.getValue(lockName);
if(myLock == null) {
myLock = new Object(); ses.putValue(lockName, myLock);
}
return myLock;
}
....
When you run any report you synchronize it on that lock Object:
synchronized(getLock(myHttpSession, "ReportsLock")) {
... create your report ...
}
Or you can use it elsewhere with:
ClassName.getLock(anHttpSessionObject, "LockName"),
where "ClassName" is the class that declares the getLock() method
previously described.
you need however to have an HttpSession instance available.
This way you can define multiple session-level locks, based
on their names. And use them for any other task than reports.
Cezar.
On Mon, 16 Aug 1999, Kapoor, Nishikant X wrote:
> Hi all
>
> I have a html form with a "Report" button that invokes the servlet that
> generates a report and presents it back to the user using 'freemarker'
> template.
> It all worked fine until I discovered (by accident) that if I open up two
> instances of the browser and click on "Report" simultaneously (almost), one
> of the two browser gets the report TWICE as long i.e. both reports
> concatenated and the other browser gets a blank output.
>
> I have tried following but the problem still persists -
>
> * Enclosed createReport() within synchronized(templateObj) like
> private boolean createReport()
> {
> synchronized (templateObj)
> {
> ...
> code to create report and populate freemarker stuff
> ...
> }
> }
>
> * defined createReport() as
> synchronized private boolean createReport()
> {
> ...
> code to create report and populate freemarker stuff
> ...
> }
>
> Can anyone help, please.
>
> I'm using Apache_1.3.6, JRun_2.3.1, Servlets_2.1 on RH_6.0.
>
> Thanks
> Nishi
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html