• 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

JSP calling POJO - Synchronization question

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

Haven't been around these parts for a while, but hoping somebody can answer something I've been puzzling over these last few days.

I have a common java object, just a POJO, that I'm calling from several JSP's. This object builds a list of data that is returned to the JSP in the form of an ArrayList - the JSP iterates thru the ArrayList and formats the output.

The POJO class has code that looks something like this:

public class MyClass {
public ArrayList getMeSomeData(String parm1, String parm2) {
// code that gets data and creates ArrayList.
return myArrayList;
}
}

In my JSP, I have the something like following in scriptlet code (NOT in declaration) :

MyClass mc = new MyClass();
List theResults = mc.getMeSomeData("xx", "xx");

Seeing as a) getMeSomeData is called from several JSP's, and b) could be called simultaneously by several users, what is the correct way to synchronize this call ?

Should I:
a) synchronize the getMeSomeData() declaration?
b) somehow synchronize within the JSP ?
c) some other method ?
d) synchronization is not necessary in this example ?

Any help greatly appreciated, many thanks in advance.
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
e) Its impossible to tell without knowing what getMeSomeData does.

My guess is that you probably don't need to synchronize though.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
f) It's impossible to say without knowing how and where the POJO is instantiated.
 
Karl Hungus
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for you swift replies guys, I'll try and answer them both:

The POJO doesn't use any database connections, or change state in any shared objects. It is not really very sophisticated, just an attempt to introduce some reusable component(s) into a heavily scripted environment. It is accessing data in a content management system (Communique), which is a java-based system where data is actually stored in flat-files.

As for the instantiation, it occurs inside a large scriptlet in a JSP file, something like this:

<%
// loads of scripted code...

MyClass mc = new MyClass();
List theResults = mc.getMeSomeData();

// lots more scripted code
%>

Hope that helps....
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since each thread will instantiate its own copy of the object, no synchronization is necessary.
 
Karl Hungus
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that, much appreciated.
 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic