• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP calling POJO - Synchronization question

 
Karl Hungus
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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.
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for that, much appreciated.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!