[Windows Mobile Development and Hacking General] Hansika:
Hi,

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

b) 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

b) 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,