You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Jaliya Ekanayake <jn...@gmail.com> on 2006/03/21 23:37:46 UTC

[Axis2] Some problems in the client side with multiple threading.

Hi Devs,

I was trying to use several axis2 clients in multiple threads and found
these problems.

1:

When clients are configured to use a separate transport listener the status
of the listener (whether started or not) is kept in the ListenerManager and
is checked by the static methods of the ClientUtils class. So this leads to
synchronization problems and gives java.net.BindException.
Solution is to synchronize the methods in the ListenerManger and the
ClientUtils classes. I can commit the fix for this.

2: NullpointerException at the AddressingOutHandler

java.lang.NullPointerException
    at
org.apache.axis2.handlers.addressing.AddressingOutHandler.isAddressingHeaderAlreadyAvailable
(AddressingOutHandler.java:407)
    at org.apache.axis2.handlers.addressing.AddressingOutHandler.invoke(
AddressingOutHandler.java:130)
    at org.apache.axis2.engine.Phase.invoke(Phase.java:378)
    at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:418)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:518)
    at org.apache.axis2.description.OutInAxisOperationClient.execute(
OutInAxisOperation.java:263)
    at org.apache.axis2.client.ServiceClient.sendReceiveNonBlocking(
ServiceClient.java:481)
    at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java
:425)
    at userguide.clients.EBLoadClient.run(EBLoadClient.java:130)
java.lang.NullPointerException

The reason for this is we keep addressingNamespaceObject in the handler
itself. So with multiple threads it produces undefined behavior.
I think we should give a better fix for this rather than synchronization.

So please have a look.

Thanks,

Jaliya

Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Eran Chinthaka <ch...@opensource.lk>.
Nothing to worry I fixed it, as soon as I saw Jaliya's mail.

I was fighting for the wording. Never mind, I had enough wars for the 
day ;-) .

-- Chinthaka


Srinath Perera wrote:
> Hi Eran;
>
> IMHO Stateless does not talk only about across multiple invocations,
> just like EJB it simply say user should not be looking at the states
> on the Handler anytime.
>
> In our initial discussion, need to avoid the syncronizing handlers was
> one of the reason to make things stateless. Stateless Handlers are the
> simple answer to avoid complexities like this.
>
> Srinath
>
> On 3/21/06, Eran Chinthaka <ch...@opensource.lk> wrote:
>   
>> Srinath Perera wrote:
>>     
>>> One of the basic assumptions of Axis2 handler architecture is that
>>> handlers are stateless .. so there should not be attributes in the
>>> class (expect for HandlerMedatadata).  Just notice
>>> AddressingOutHandler has a attribute that leads to this unpleasant
>>> surprise
>>>
>>>       
>> Hmm, I think I have done a mistake. But it has nothing to do with the
>> assumption of handlers being stateless, IMO.
>>
>> I have not kept this attribute across multiple invocations of the same
>> handler. Its *within* one invocation of that handler.
>>
>> Anyway, if this leads to synchronization issues, let me keep this in the
>> message context.
>>
>> -- Chinthaka
>>
>>     
>
>
> --
> ============================
> Srinath Perera:
>    http://www.cs.indiana.edu/~hperera/
>    http://www.bloglines.com/blog/hemapani
>
>   


Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Srinath Perera <he...@gmail.com>.
cool!!   :), when I looked at the code yesterday (when jaliya
mentioned the problem) I saw it and thought it is better to discuss it
in the list ... so other deveopers get to know about the stateless
assumptions we made.
Thanks
Srinath




On 3/22/06, Eran Chinthaka <ch...@opensource.lk> wrote:
> You being one of the pioneers in Axis2, how can you talk abt some old
> code ?  ;-) Get an svn up and you will see they are no more like that.
>
> Srinath Perera wrote:
> >>> On 3/21/06, Eran Chinthaka <ch...@opensource.lk> wrote:
> >>>
> >>>> I have not kept this attribute across multiple invocations of the same
> >>>> handler. Its *within* one invocation of that handler.
> >>>>
> >> Are you keeping an instance var that holds some value across two or more
> >> methods in the same handler? That is, do you use an instance var to pass
> >> some state from the main method to other methods? If so that will lead
> >> to problems and can easily be fixed with params.
> >>
> >> If not I'm confused what the offending thing is; can someone point out
> >> the code please.
> >>
> > the class is org.apache.axis2.handlers.addressing.AddressingOutHandler,
> >
> > offending part is (following is yesterdays code) Handler attributes
> > addressingNamespaceObject and msgCtxt .. they remember things between
> > the method invocations (addressingNamespaceObject accsessed by most
> > method without passing it in .. e.g.
> > processToEPRReferenceInformation(....)) and run in to trouble
> >
> > anothor thought .. we should be careful when hanging to the
> > messagecontext from some instance varaible as that might lead to
> > memeory leaks if object  (e.g. Handler) is never garbage collected
> >
> > Thanks
> > Srinath
> >
> > public class AddressingOutHandler extends AddressingHandler {
> >    ..............
> >     protected OMNamespace addressingNamespaceObject;
> >     private MessageContext msgCtxt;
> >     public void invoke(MessageContext msgContext) throws AxisFault {
> >                         .....................
> >     }
> >  }
> >
> > --
> > ============================
> > Srinath Perera:
> >    http://www.cs.indiana.edu/~hperera/
> >    http://www.bloglines.com/blog/hemapani
> >
> >
>
>


--
============================
Srinath Perera:
   http://www.cs.indiana.edu/~hperera/
   http://www.bloglines.com/blog/hemapani

Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Eran Chinthaka <ch...@opensource.lk>.
You being one of the pioneers in Axis2, how can you talk abt some old 
code ?  ;-) Get an svn up and you will see they are no more like that.

Srinath Perera wrote:
>>> On 3/21/06, Eran Chinthaka <ch...@opensource.lk> wrote:
>>>       
>>>> I have not kept this attribute across multiple invocations of the same
>>>> handler. Its *within* one invocation of that handler.
>>>>         
>> Are you keeping an instance var that holds some value across two or more
>> methods in the same handler? That is, do you use an instance var to pass
>> some state from the main method to other methods? If so that will lead
>> to problems and can easily be fixed with params.
>>
>> If not I'm confused what the offending thing is; can someone point out
>> the code please.
>>     
> the class is org.apache.axis2.handlers.addressing.AddressingOutHandler,
>
> offending part is (following is yesterdays code) Handler attributes
> addressingNamespaceObject and msgCtxt .. they remember things between
> the method invocations (addressingNamespaceObject accsessed by most
> method without passing it in .. e.g.
> processToEPRReferenceInformation(....)) and run in to trouble
>
> anothor thought .. we should be careful when hanging to the
> messagecontext from some instance varaible as that might lead to
> memeory leaks if object  (e.g. Handler) is never garbage collected
>
> Thanks
> Srinath
>
> public class AddressingOutHandler extends AddressingHandler {
>    ..............
>     protected OMNamespace addressingNamespaceObject;
>     private MessageContext msgCtxt;
>     public void invoke(MessageContext msgContext) throws AxisFault {
>                         .....................
>     }
>  }
>
> --
> ============================
> Srinath Perera:
>    http://www.cs.indiana.edu/~hperera/
>    http://www.bloglines.com/blog/hemapani
>
>   


Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Srinath Perera <he...@gmail.com>.
> > On 3/21/06, Eran Chinthaka <ch...@opensource.lk> wrote:
> > >
> > > I have not kept this attribute across multiple invocations of the same
> > > handler. Its *within* one invocation of that handler.
>
> Are you keeping an instance var that holds some value across two or more
> methods in the same handler? That is, do you use an instance var to pass
> some state from the main method to other methods? If so that will lead
> to problems and can easily be fixed with params.
>
> If not I'm confused what the offending thing is; can someone point out
> the code please.
the class is org.apache.axis2.handlers.addressing.AddressingOutHandler,

offending part is (following is yesterdays code) Handler attributes
addressingNamespaceObject and msgCtxt .. they remember things between
the method invocations (addressingNamespaceObject accsessed by most
method without passing it in .. e.g.
processToEPRReferenceInformation(....)) and run in to trouble

anothor thought .. we should be careful when hanging to the
messagecontext from some instance varaible as that might lead to
memeory leaks if object  (e.g. Handler) is never garbage collected

Thanks
Srinath

public class AddressingOutHandler extends AddressingHandler {
   ..............
    protected OMNamespace addressingNamespaceObject;
    private MessageContext msgCtxt;
    public void invoke(MessageContext msgContext) throws AxisFault {
                        .....................
    }
 }

--
============================
Srinath Perera:
   http://www.cs.indiana.edu/~hperera/
   http://www.bloglines.com/blog/hemapani

Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
On Wed, 2006-03-22 at 07:01 -0500, Srinath Perera wrote:
> Hi Eran;
> 
> IMHO Stateless does not talk only about across multiple invocations,
> just like EJB it simply say user should not be looking at the states
> on the Handler anytime.

+1.

> On 3/21/06, Eran Chinthaka <ch...@opensource.lk> wrote:
> >
> > I have not kept this attribute across multiple invocations of the same
> > handler. Its *within* one invocation of that handler.

Are you keeping an instance var that holds some value across two or more
methods in the same handler? That is, do you use an instance var to pass
some state from the main method to other methods? If so that will lead
to problems and can easily be fixed with params.

If not I'm confused what the offending thing is; can someone point out
the code please.

> > Anyway, if this leads to synchronization issues, let me keep this in the
> > message context.

That'll work; of course.

Sanjiva.



Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Srinath Perera <he...@gmail.com>.
Hi Eran;

IMHO Stateless does not talk only about across multiple invocations,
just like EJB it simply say user should not be looking at the states
on the Handler anytime.

In our initial discussion, need to avoid the syncronizing handlers was
one of the reason to make things stateless. Stateless Handlers are the
simple answer to avoid complexities like this.

Srinath

On 3/21/06, Eran Chinthaka <ch...@opensource.lk> wrote:
>
> Srinath Perera wrote:
> > One of the basic assumptions of Axis2 handler architecture is that
> > handlers are stateless .. so there should not be attributes in the
> > class (expect for HandlerMedatadata).  Just notice
> > AddressingOutHandler has a attribute that leads to this unpleasant
> > surprise
> >
> Hmm, I think I have done a mistake. But it has nothing to do with the
> assumption of handlers being stateless, IMO.
>
> I have not kept this attribute across multiple invocations of the same
> handler. Its *within* one invocation of that handler.
>
> Anyway, if this leads to synchronization issues, let me keep this in the
> message context.
>
> -- Chinthaka
>


--
============================
Srinath Perera:
   http://www.cs.indiana.edu/~hperera/
   http://www.bloglines.com/blog/hemapani

Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Eran Chinthaka <ch...@opensource.lk>.
Srinath Perera wrote:
> One of the basic assumptions of Axis2 handler architecture is that
> handlers are stateless .. so there should not be attributes in the
> class (expect for HandlerMedatadata).  Just notice
> AddressingOutHandler has a attribute that leads to this unpleasant
> surprise
>   
Hmm, I think I have done a mistake. But it has nothing to do with the 
assumption of handlers being stateless, IMO.

I have not kept this attribute across multiple invocations of the same 
handler. Its *within* one invocation of that handler.

Anyway, if this leads to synchronization issues, let me keep this in the 
message context.

-- Chinthaka

Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Srinath Perera <he...@gmail.com>.
One of the basic assumptions of Axis2 handler architecture is that
handlers are stateless .. so there should not be attributes in the
class (expect for HandlerMedatadata).  Just notice
AddressingOutHandler has a attribute that leads to this unpleasant
surprise

We should be writing a Handler developer guide :) .. for the time
being lets follow the stateless principal in the future (if there is a
state to be stored .. it should be at appropriate context )

Srinath

On 3/21/06, Davanum Srinivas <da...@gmail.com> wrote:
> Jaliya,
>
> +1 to #1. Please commit the fix.
>
> -- dims
>
> On 3/21/06, Jaliya Ekanayake <jn...@gmail.com> wrote:
> > Hi Devs,
> >
> > I was trying to use several axis2 clients in multiple threads and found
> > these problems.
> >
> > 1:
> >
> > When clients are configured to use a separate transport listener the status
> > of the listener (whether started or not) is kept in the ListenerManager and
> > is checked by the static methods of the ClientUtils class. So this leads to
> > synchronization problems and gives java.net.BindException.
> > Solution is to synchronize the methods in the ListenerManger and the
> > ClientUtils classes. I can commit the fix for this.
> >
> > 2: NullpointerException at the AddressingOutHandler
> >
> > java.lang.NullPointerException
> >     at
> > org.apache.axis2.handlers.addressing.AddressingOutHandler.isAddressingHeaderAlreadyAvailable(AddressingOutHandler.java:407)
> >     at
> > org.apache.axis2.handlers.addressing.AddressingOutHandler.invoke(AddressingOutHandler.java
> > :130)
> >     at org.apache.axis2.engine.Phase.invoke(Phase.java:378)
> >     at
> > org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:418)
> >     at
> > org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:518)
> >     at
> > org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:263)
> >     at
> > org.apache.axis2.client.ServiceClient.sendReceiveNonBlocking(ServiceClient.java:481)
> >     at org.apache.axis2.client.ServiceClient.sendReceive
> > (ServiceClient.java:425)
> >     at
> > userguide.clients.EBLoadClient.run(EBLoadClient.java:130)
> > java.lang.NullPointerException
> >
> > The reason for this is we keep addressingNamespaceObject in the handler
> > itself. So with multiple threads it produces undefined behavior.
> > I think we should give a better fix for this rather than synchronization.
> >
> > So please have a look.
> >
> > Thanks,
> >
> > Jaliya
> >
> >
> >
>
>
> --
> Davanum Srinivas : http://wso2.com/blogs/
>


--
============================
Srinath Perera:
   http://www.cs.indiana.edu/~hperera/
   http://www.bloglines.com/blog/hemapani

Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Jaliya Ekanayake <jn...@gmail.com>.
Done.
-Jaliya
----- Original Message ----- 
From: "Davanum Srinivas" <da...@gmail.com>
To: <ax...@ws.apache.org>
Sent: Tuesday, March 21, 2006 5:40 PM
Subject: Re: [Axis2] Some problems in the client side with multiple 
threading.


Jaliya,

+1 to #1. Please commit the fix.

-- dims

On 3/21/06, Jaliya Ekanayake <jn...@gmail.com> wrote:
> Hi Devs,
>
> I was trying to use several axis2 clients in multiple threads and found
> these problems.
>
> 1:
>
> When clients are configured to use a separate transport listener the 
> status
> of the listener (whether started or not) is kept in the ListenerManager 
> and
> is checked by the static methods of the ClientUtils class. So this leads 
> to
> synchronization problems and gives java.net.BindException.
> Solution is to synchronize the methods in the ListenerManger and the
> ClientUtils classes. I can commit the fix for this.
>
> 2: NullpointerException at the AddressingOutHandler
>
> java.lang.NullPointerException
>     at
> org.apache.axis2.handlers.addressing.AddressingOutHandler.isAddressingHeaderAlreadyAvailable(AddressingOutHandler.java:407)
>     at
> org.apache.axis2.handlers.addressing.AddressingOutHandler.invoke(AddressingOutHandler.java
> :130)
>     at org.apache.axis2.engine.Phase.invoke(Phase.java:378)
>     at
> org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:418)
>     at
> org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:518)
>     at
> org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:263)
>     at
> org.apache.axis2.client.ServiceClient.sendReceiveNonBlocking(ServiceClient.java:481)
>     at org.apache.axis2.client.ServiceClient.sendReceive
> (ServiceClient.java:425)
>     at
> userguide.clients.EBLoadClient.run(EBLoadClient.java:130)
> java.lang.NullPointerException
>
> The reason for this is we keep addressingNamespaceObject in the handler
> itself. So with multiple threads it produces undefined behavior.
> I think we should give a better fix for this rather than synchronization.
>
> So please have a look.
>
> Thanks,
>
> Jaliya
>
>
>


--
Davanum Srinivas : http://wso2.com/blogs/


Re: [Axis2] Some problems in the client side with multiple threading.

Posted by Davanum Srinivas <da...@gmail.com>.
Jaliya,

+1 to #1. Please commit the fix.

-- dims

On 3/21/06, Jaliya Ekanayake <jn...@gmail.com> wrote:
> Hi Devs,
>
> I was trying to use several axis2 clients in multiple threads and found
> these problems.
>
> 1:
>
> When clients are configured to use a separate transport listener the status
> of the listener (whether started or not) is kept in the ListenerManager and
> is checked by the static methods of the ClientUtils class. So this leads to
> synchronization problems and gives java.net.BindException.
> Solution is to synchronize the methods in the ListenerManger and the
> ClientUtils classes. I can commit the fix for this.
>
> 2: NullpointerException at the AddressingOutHandler
>
> java.lang.NullPointerException
>     at
> org.apache.axis2.handlers.addressing.AddressingOutHandler.isAddressingHeaderAlreadyAvailable(AddressingOutHandler.java:407)
>     at
> org.apache.axis2.handlers.addressing.AddressingOutHandler.invoke(AddressingOutHandler.java
> :130)
>     at org.apache.axis2.engine.Phase.invoke(Phase.java:378)
>     at
> org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:418)
>     at
> org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:518)
>     at
> org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:263)
>     at
> org.apache.axis2.client.ServiceClient.sendReceiveNonBlocking(ServiceClient.java:481)
>     at org.apache.axis2.client.ServiceClient.sendReceive
> (ServiceClient.java:425)
>     at
> userguide.clients.EBLoadClient.run(EBLoadClient.java:130)
> java.lang.NullPointerException
>
> The reason for this is we keep addressingNamespaceObject in the handler
> itself. So with multiple threads it produces undefined behavior.
> I think we should give a better fix for this rather than synchronization.
>
> So please have a look.
>
> Thanks,
>
> Jaliya
>
>
>


--
Davanum Srinivas : http://wso2.com/blogs/