Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Global Var. sync issue

 
sean cee
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, access by two threads at the same time can be a problem. Just synchronize access to the variable.
------------------
Bosun
SCJP for the Java� 2 Platform
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Adam
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic