Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


Java-related question: thread safe ActionClasses

  • Please log in to reply
No replies to this topic

#1 Hansika


  • Members
  • 1 posts
  • Local time:01:07 AM

Posted 14 April 2009 - 06:14 AM


I've got a question about an issue to the thread safe execution.
The whole setup was made in order to have a business logic triggered by
struts, that still can retrieve information from its environment -- here Struts -- without
having explicit knowledge of it. In short, the processing is like this:

a) the ActionObject gets the business object
:thumbsup: calls the business method on the business object including
-the HttpServletRequest just received in the perform call, and
-a reference to itself
c) the business object now uses this reference to retrieve from this object
some information about the business objects environment. Thus, the business object
calls the ActionObject (without knowing, that it is a struts Action) and hands in
the HttpServletRequest (as an java.lang.Object).
d) the ActionObject uses the HttpServletRequest to get the desired information
(like request.getParameter()) and returns the result back to the business object.

Basically, I want to know, if I can use a static method (no static fields) within the ActionObject
for performing the environment lookup thread safe.

Sounds a little complicated, doesn't it? Well, to those who have the time to get involved.
It's actually not that difficult.

The class structure in my struts app is like the following:

-Class MyActionClass: extends ...struts.Action implements myClasses.Environment

-Interface myClasses.Environment has (let's say) just one method:
public boolean isPropertySet(Object helperObject)

-Class DoSomeStuffRq is a class that contains
a)translated form data, and
:flowers: an java.lang.Object reference to store the HttpServletRequest
(which the MyActionObject just has recieved in its perform method).

-Class MyBusinessClass: doSomeBusinessStuff(DoSomeStuffRq stuffInfo, Environment env)

The Environment interface is there in order to decouple Struts from the business logic - giving
the chance to reuse the MyBusinessClass when not using Struts anymore (well, I hope I don't
have to, but still).

So finer grained, the actions are:

1) Let the MyActionClass get the businessObject (of type MyBusinessClass),
2) MyActionClass calls the method businessObject.doSomeBusinessStuff(stuffInfo, this);
["this" is of type Environment]

3) in order to process the business actions, the BusinessObject has to
retrieve a boolean value from it's (unknown) environment. So it calls
the isPropertySet from the Environment interface (which has the MyActionClass implementation):

public StuffResponse doSomeBusinessStuff(DoSomeStuffRq stuffInfo, Environment env)
boolean importantProperty = environment.isPropertySet(stuffInfo.getObjectReference());

where stuffInfo.getObjectReference() gives the above mentioned HttpServletRequest reference
as a java.lang.Object.

4) the rest is quite obvious: myActionObject does a cast of the java.lang.Object to the HttpServletRequest

and gets a request parameter. Then, it returns a boolean value depending on that request parameter.

Well, there's lots to argue about in the whole scenario.
Questions like: does it make sense to do all that stuff to decouple business logic and Struts;
is there
a better way of passing the parameters between the objects, shall the MyActionClass handle
the lookup,
when all I need is a HttpServletRequest and so on.
But the simple question I'm interested in is: Can I have the MyActionClass' method
public boolean isPropertySet(Object helperObject)
being static?

I think, I can, because:
As long as I don't use any class members in the MyActionClass, the thread safety shall be

given -- no matter if the method is static or not. Is that true?
Well it's more a java related question, but I think there are some people here, who are interested
in this issue too.

Thanks in advance for your time,

BC AdBot (Login to Remove)


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users