variables

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

variables

Jad El Omeiri
Hello there,


I have a conceptual question here.

I have my code logic written in Events. And I have variables that are used across different methods.
I initially had all my variables as static so that my methods can directly alter their values, but I also made them private so they are only accessed from my own class.

I have just been told that this would not be safe for multi-users. I thought of removing the static for all variables, and then just create setters & getters.

But again, I'm being told that this is not safe and that this is not how it should be done in Ofbiz.

I'm being told to use http requests or hidden variables for my variables.


What do you think about that guys?


Cheers
Jad El Omeiri
Reply | Threaded
Open this post in threaded view
|

Re: variables

vyom0213@gmail.com
Hi,

What you have been told is valid for any multi-threaded application.
You can find good examples of usage of OFBiz Events in
framework/common/src/org/ofbiz/common/CommonEvents.java. A common pattern
is to use 'constants' as a static/ shared variables.

A lot of depends on what you are implementing, one can pass hidden
variables during form submissions, though in some cases data is often
implicitly present in the HttpServletRequest argument.

--
Vyom


On 20 March 2014 16:09, Jad El Omeiri <[hidden email]> wrote:

> Hello there,
>
>
> I have a conceptual question here.
>
> I have my code logic written in Events. And I have variables that are used
> across different methods.
> I initially had all my variables as static so that my methods can directly
> alter their values, but I also made them private so they are only accessed
> from my own class.
>
> I have just been told that this would not be safe for multi-users. I
> thought
> of removing the static for all variables, and then just create setters &
> getters.
>
> But again, I'm being told that this is not safe and that this is not how it
> should be done in Ofbiz.
>
> I'm being told to use http requests or hidden variables for my variables.
>
>
> What do you think about that guys?
>
>
> Cheers
>
>
>
> -----
> Jad El Omeiri
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/variables-tp4649568.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
--
Vyom
Reply | Threaded
Open this post in threaded view
|

Re: variables

Jad El Omeiri
Ok thanks a lot Vyom. I actually thought that session would have its own copy of the variables. But apparently that is not the case. I will into CommonEvents.java.

Thank you!
Jad El Omeiri