• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet interprocess communication

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my problem goes like this:
i want to create an objest, a class actually, and then put it in the memory. then, there will be one servlet that manipulate, get and set the variable in that class. after that, or at the same time, there will be another servlet that take a value from the object and then print it. how can i do that?..
i tried getServletContext().setAttribute(name, object), but it seem like it only holding the copy of the object, not the reference. so that, any changes that i made after calling setAttribute will not affected the object which in the memory....
Help!.....
 
Saloon Keeper
Posts: 27879
197
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That didn't completely translate, but one solution is to make the object an Enterprise JavaBean. EJB's have builtin transaction support and serialized access to the object's methods - including the set/get methods.
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm not sure that the heavy weight approach of EJBs is required here.
In my company we often tie objects to the Application Context - object pools and the like. As long as you ensure that the modification is thread-safe then there isn't usually a problem.
I would say that you should ensure that you are storing a reference to your object in the Application context rather than the object itself.
Cheers,
Steve
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets not get too far afield with our nomenclature here. You always store a reference to an object, not the "object itself". Unless you are serializing the object to a file or something, the JVM memory mangagement handles where the object actually lives.


i tried getServletContext().setAttribute(name, object), but it seem like it only holding the copy of the object, not the reference. so that, any changes that i made after calling setAttribute will not affected the object which in the memory....


If you didn't clone the object, there is still only one instance and changes should be visible where ever there is a reference to it. I am betting your problem lies elsewhere.
Bill
 
Ariffin Ahmad
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Granton:
Hi,
I'm not sure that the heavy weight approach of EJBs is required here.
In my company we often tie objects to the Application Context - object pools and the like. As long as you ensure that the modification is thread-safe then there isn't usually a problem.
I would say that you should ensure that you are storing a reference to your object in the Application context rather than the object itself.
Cheers,
Steve


can u please show me an example on how to do it that way....
 
Ariffin Ahmad
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
Lets not get too far afield with our nomenclature here. You always store a reference to an object, not the "object itself". Unless you are serializing the object to a file or something, the JVM memory mangagement handles where the object actually lives.

If you didn't clone the object, there is still only one instance and changes should be visible where ever there is a reference to it. I am betting your problem lies elsewhere.
Bill


my code was like this...
on first servlet:

on second servlet..

what happen was, even i did something on someClass in the first servlet, i can't get changes in second servlet after i called setAttribute.
any advices?
 
reply
    Bookmark Topic Watch Topic
  • New Topic