my dog learned polymorphism
The moose likes Servlets and the fly likes Global Var.  sync issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Global Var.  sync issue" Watch "Global Var.  sync issue" New topic

Global Var. sync issue

sean cee
Ranch Hand

Joined: Oct 24, 2000
Posts: 115
Hi all,
with my servlet application, I need to make use of application variable.
Each request for the servlet will need an access to application variable and add some data to application var. and store back.
but what if two requests were made at the same time? Can this be an issue like in Java Multithreaded application ?
or does servelt engine handle this?
Thanks in advance

Sean <br />SCJP2, SCJP2p1.4, SCWCD
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yes, access by two threads at the same time can be a problem. Just synchronize access to the variable.
SCJP for the Java� 2 Platform

So much trouble in the world -- Bob Marley
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 567
Originally posted by Bosun Bello:
Yes, access by two threads at the same time can be a problem. Just synchronize access to the variable.

Is this dependent on the server? I mean I can understand that Tomcat requires it, but I would have thought the Weblogic would take care of it for the Application object.

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

Why should it be? Multithreading support as a means is a core component of Java. EJBs have their innards protected -- from EXTERNAL synchronization issues -- as part of the remoting process, but servlets are just classes and they are quite capable of being managed by the much lighter weight facilities that are built into Java.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Global Var. sync issue
It's not a secret anymore!