agora inbox for pljava-dev@postgresql.org
help / color / mirror / Atom feed[Pljava-dev] static variables
3+ messages / 0 participants
[nested] [flat]
* [Pljava-dev] static variables
@ 2007-03-12 22:52
0 siblings, 1 reply; 3+ messages in thread
From: @ 2007-03-12 22:52 UTC (permalink / raw)
I've been starting to use pljava and find it very useful, but there's
something I want to know if it's possible. I want to have a static
variable that I can set and retrieve during a session. Something like
this:
public static String x;
public static String test() {
if (x==null) {
return "";
}
return x;
}
public static String testString(String me) {
x=me;
return me;
}
This is a trivial example, but what I want to do on the long run is to
setup a XML parser once (per session) and to avoid the overhead for
each calling of the function. Is it possible?
Thanks a lot,
Andres
^ permalink raw reply [nested|flat] 3+ messages in thread
* [Pljava-dev] static variables
@ 2007-03-13 07:44
parent:
0 siblings, 1 reply; 3+ messages in thread
From: @ 2007-03-13 07:44 UTC (permalink / raw)
I can't see any reason why you can't use static variables.
Just make sure that the variable is thread safe, as multiple threads
will be accessing it concurrently.
From looking at your code. Imagine 2 threads call your setter function,
then call the test() function. One of the threads will be using the
incorrect String (I guess?). So in this case using static variables
would probably produce unexpected results!
Andres Olarte wrote:
> I've been starting to use pljava and find it very useful, but there's
> something I want to know if it's possible. I want to have a static
> variable that I can set and retrieve during a session. Something like
> this:
>
> public static String x;
>
> public static String test() {
> if (x==null) {
> return "";
> }
> return x;
> }
>
> public static String testString(String me) {
> x=me;
> return me;
> }
>
> This is a trivial example, but what I want to do on the long run is to
> setup a XML parser once (per session) and to avoid the overhead for
> each calling of the function. Is it possible?
>
> Thanks a lot,
>
> Andres
> _______________________________________________
> Pljava-dev mailing list
> Pljava-dev at gborg.postgresql.org
> http://gborg.postgresql.org/mailman/listinfo/pljava-dev
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* [Pljava-dev] static variables
@ 2007-03-13 17:51
parent:
0 siblings, 0 replies; 3+ messages in thread
From: @ 2007-03-13 17:51 UTC (permalink / raw)
Why thread safe? As far as I understand the architecture of pljava,
every connection has it's private JVM, therefore each tread (or
connection) will access each own variable. Since I don't want to
share the private static variable among connections, it should work.
Anybody has any experience with this?
On 3/12/07, Peter Henderson <peter.henderson at starjar.com> wrote:
> I can't see any reason why you can't use static variables.
>
> Just make sure that the variable is thread safe, as multiple threads
> will be accessing it concurrently.
>
> From looking at your code. Imagine 2 threads call your setter function,
> then call the test() function. One of the threads will be using the
> incorrect String (I guess?). So in this case using static variables
> would probably produce unexpected results!
>
>
> Andres Olarte wrote:
> > I've been starting to use pljava and find it very useful, but there's
> > something I want to know if it's possible. I want to have a static
> > variable that I can set and retrieve during a session. Something like
> > this:
> >
> > public static String x;
> >
> > public static String test() {
> > if (x==null) {
> > return "";
> > }
> > return x;
> > }
> >
> > public static String testString(String me) {
> > x=me;
> > return me;
> > }
> >
> > This is a trivial example, but what I want to do on the long run is to
> > setup a XML parser once (per session) and to avoid the overhead for
> > each calling of the function. Is it possible?
> >
> > Thanks a lot,
> >
> > Andres
> > _______________________________________________
> > Pljava-dev mailing list
> > Pljava-dev at gborg.postgresql.org
> > http://gborg.postgresql.org/mailman/listinfo/pljava-dev
> >
>
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-03-13 17:51 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-03-12 22:52 [Pljava-dev] static variables
2007-03-13 07:44 `
2007-03-13 17:51 `
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox