You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Marco Spinetti <m....@pisa.iol.it> on 2003/09/01 12:47:00 UTC

Init Parameter

Hi I need to read some configuration parameter, so reading some mails in
mail list I have written:

MessageContext msgContext = MessageContext.getContext();
    SOAPService    service    = msgContext.getService();
    paramValue         = service.getOption("paramName");

and I have inserted <parameter ..../> to my service.

I have discovered that you can't insert this code in a static block, (http://marc.theaimsgroup.com/?t=104765761500001&r=1&w=2) 

so I try to insert it in the constructor of my class with my SOAP method.

But I see that the constructor is called every invocation of my web service, so could
someone explain me how to initialize a variable one time and only one time?

Cheers

--Marco






RE: Init Parameter

Posted by Robert Lowe <rm...@rmlowe.com>.
It should be enough to put the init code in a block that is synchronized on
the class, e.g.

class Foo {

   static boolean isInitialized = false;

   public Foo(...) {
     synchronized (Foo.class) {
       if (!Foo.isInitialized) {
         .. do init stuff as below ..
       }
     }
     ....
   }

}

- Rob


-----Original Message-----
From: Marco Spinetti [mailto:m.spinetti@pisa.iol.it]
Sent: Monday, September 01, 2003 7:52 PM
To: axis-user@ws.apache.org
Subject: Re: Init Parameter


I'm missing something......

In a multi-thread environment, you need a kind of critical region
mechanism.

If two clients call, in the same instant, your web service (two
instances of your object ----> 2 constructor, your code is executed
twice because the statement (in this example "Foo.isInitialized") is
true.

The target of static block is to execute some code once.

But it seems that in axis enviroment, initializing star-up parameters is
not obvious.

Can someone give me some hints?


--Marco



Il lun, 2003-09-01 alle 12:59, Tom Oinn ha scritto:
> class Foo {
>
>    static boolean isInitialized = false;
>
>    public Foo(...) {
>      if (Foo.isInitialized) {
>        .. do init stuff as below ..
>      }
>      ....
>    }
>
> }
>
> ...or am I missing something?
>
> Tom
>
> Marco Spinetti wrote:
> > Hi I need to read some configuration parameter, so reading some mails in
> > mail list I have written:
> >
> > MessageContext msgContext = MessageContext.getContext();
> >     SOAPService    service    = msgContext.getService();
> >     paramValue         = service.getOption("paramName");
> >
> > and I have inserted <parameter ..../> to my service.
> >
> > I have discovered that you can't insert this code in a static block,
(http://marc.theaimsgroup.com/?t=104765761500001&r=1&w=2)
> >
> > so I try to insert it in the constructor of my class with my SOAP
method.
> >
> > But I see that the constructor is called every invocation of my web
service, so could
> > someone explain me how to initialize a variable one time and only one
time?
> >
> > Cheers
> >
> > --Marco
> >
> >
> >
> >
> >
>
>




Re: Init Parameter

Posted by Marco Spinetti <m....@pisa.iol.it>.
I'm missing something......

In a multi-thread environment, you need a kind of critical region
mechanism.

If two clients call, in the same instant, your web service (two
instances of your object ----> 2 constructor, your code is executed
twice because the statement (in this example "Foo.isInitialized") is
true.

The target of static block is to execute some code once.

But it seems that in axis enviroment, initializing star-up parameters is
not obvious.

Can someone give me some hints?


--Marco



Il lun, 2003-09-01 alle 12:59, Tom Oinn ha scritto:
> class Foo {
> 
>    static boolean isInitialized = false;
> 
>    public Foo(...) {
>      if (Foo.isInitialized) {
>        .. do init stuff as below ..
>      }
>      ....
>    }
> 
> }
> 
> ...or am I missing something?
> 
> Tom
> 
> Marco Spinetti wrote:
> > Hi I need to read some configuration parameter, so reading some mails in
> > mail list I have written:
> > 
> > MessageContext msgContext = MessageContext.getContext();
> >     SOAPService    service    = msgContext.getService();
> >     paramValue         = service.getOption("paramName");
> > 
> > and I have inserted <parameter ..../> to my service.
> > 
> > I have discovered that you can't insert this code in a static block, (http://marc.theaimsgroup.com/?t=104765761500001&r=1&w=2) 
> > 
> > so I try to insert it in the constructor of my class with my SOAP method.
> > 
> > But I see that the constructor is called every invocation of my web service, so could
> > someone explain me how to initialize a variable one time and only one time?
> > 
> > Cheers
> > 
> > --Marco
> > 
> > 
> > 
> > 
> > 
> 
> 


Re: Init Parameter

Posted by Tom Oinn <tm...@ebi.ac.uk>.
class Foo {

   static boolean isInitialized = false;

   public Foo(...) {
     if (Foo.isInitialized) {
       .. do init stuff as below ..
     }
     ....
   }

}

...or am I missing something?

Tom

Marco Spinetti wrote:
> Hi I need to read some configuration parameter, so reading some mails in
> mail list I have written:
> 
> MessageContext msgContext = MessageContext.getContext();
>     SOAPService    service    = msgContext.getService();
>     paramValue         = service.getOption("paramName");
> 
> and I have inserted <parameter ..../> to my service.
> 
> I have discovered that you can't insert this code in a static block, (http://marc.theaimsgroup.com/?t=104765761500001&r=1&w=2) 
> 
> so I try to insert it in the constructor of my class with my SOAP method.
> 
> But I see that the constructor is called every invocation of my web service, so could
> someone explain me how to initialize a variable one time and only one time?
> 
> Cheers
> 
> --Marco
> 
> 
> 
> 
> 



Re: Init Parameter

Posted by Tom Oinn <tm...@ebi.ac.uk>.
um, apologies for obviously incorrect code, but you see what I mean :)

Ciao,

Tom