You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Martin Funk <ma...@gmail.com> on 2014/03/06 17:42:45 UTC

What is the meaning of: javax.ejb.Stateless

Hi again,

still at a very early stage of conquering the domain of TomEE+.

I have a question on javax.ejb.Stateless. In the specs I read that in the area of SOAP based web services, which are implemented by an EJB component the class implementing the endpoint must be annotated @Stateless or @Singleton.

I got curious on what would happen if the class was annotated @Statless even though the instances were not 'Stateless'
Exceptions were expected, but non were thrown.

Code Service:
package de.jaxws.soap.ejb;

import javax.ejb.Stateless;
import javax.jws.WebService;

@WebService
@Stateless
public class SoapEjb {

	private int i;

	public String helloEJB() {
		return "helloEJB again :" + i++;
	}
}

Code Client (supporting Classes were generated using wsimport):
package de.jaxws.soap.client;


import de.jaxws.soap.client.SoapEjb;
import de.jaxws.soap.client.SoapEjbService;

public class Client {

	public static void main(String[] args) {

		SoapEjbService service = new SoapEjbService();
		SoapEjb port = service.getPort(SoapEjb.class);
		for (int i = 0; i < 10; i++) {
			System.out.println(port.helloEJB());
		}
	}

}

Output of Client:
helloEJB again :0
helloEJB again :1
helloEJB again :2
helloEJB again :3
helloEJB again :4
helloEJB again :5
helloEJB again :6
helloEJB again :7
helloEJB again :8
helloEJB again :9

Could someone please give me a hint on what I'm misunderstanding?

Cheers,

Martin

Re: What is the meaning of: javax.ejb.Stateless

Posted by Romain Manni-Bucau <rm...@gmail.com>.
stateless beans are behind a pool for sure async or not and that's for
years (openejb 3 at least).
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-03-06 18:00 GMT+01:00 Howard W. Smith, Jr. <sm...@gmail.com>:
> Romain, I think there has been some [recent] discussion on this user/mail
> list, and I think it was mentioned that there is 3 async thread/instances
> in the pool, and/so it may be likely that @Stateless beans may be
> used/referenced.
>
> in the past, earlier versions of tomee [1.6.0 final and snapshot releases],
> it seemed as though my @Stateless beans were referenced again and again,
> and data retrieved from database via these @Stateless beans...were not
> updated.
>
> i'm using January 2014 version of tomee 1.6.1 snapshot, now, and i don't
> see this behavior any more, and now my @stateless beans seem to be meeting
> [my] expectations [now]. of course, i'm happy about that.
>
>
>
> On Thu, Mar 6, 2014 at 11:47 AM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
>> actually if you stress a bit your app you'll see it is not the case,
>> in a single threaded case you can be lucky :)
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>>
>> 2014-03-06 17:45 GMT+01:00 José Luis Cetina <ma...@gmail.com>:
>> > I guess the container is giving you the same ejb thats why have some
>> state.
>> >
>> >
>> > 2014-03-06 10:42 GMT-06:00 Martin Funk <ma...@gmail.com>:
>> >
>> >> Hi again,
>> >>
>> >> still at a very early stage of conquering the domain of TomEE+.
>> >>
>> >> I have a question on javax.ejb.Stateless. In the specs I read that in
>> the
>> >> area of SOAP based web services, which are implemented by an EJB
>> component
>> >> the class implementing the endpoint must be annotated @Stateless or
>> >> @Singleton.
>> >>
>> >> I got curious on what would happen if the class was annotated @Statless
>> >> even though the instances were not 'Stateless'
>> >> Exceptions were expected, but non were thrown.
>> >>
>> >> Code Service:
>> >> package de.jaxws.soap.ejb;
>> >>
>> >> import javax.ejb.Stateless;
>> >> import javax.jws.WebService;
>> >>
>> >> @WebService
>> >> @Stateless
>> >> public class SoapEjb {
>> >>
>> >>         private int i;
>> >>
>> >>         public String helloEJB() {
>> >>                 return "helloEJB again :" + i++;
>> >>         }
>> >> }
>> >>
>> >> Code Client (supporting Classes were generated using wsimport):
>> >> package de.jaxws.soap.client;
>> >>
>> >>
>> >> import de.jaxws.soap.client.SoapEjb;
>> >> import de.jaxws.soap.client.SoapEjbService;
>> >>
>> >> public class Client {
>> >>
>> >>         public static void main(String[] args) {
>> >>
>> >>                 SoapEjbService service = new SoapEjbService();
>> >>                 SoapEjb port = service.getPort(SoapEjb.class);
>> >>                 for (int i = 0; i < 10; i++) {
>> >>                         System.out.println(port.helloEJB());
>> >>                 }
>> >>         }
>> >>
>> >> }
>> >>
>> >> Output of Client:
>> >> helloEJB again :0
>> >> helloEJB again :1
>> >> helloEJB again :2
>> >> helloEJB again :3
>> >> helloEJB again :4
>> >> helloEJB again :5
>> >> helloEJB again :6
>> >> helloEJB again :7
>> >> helloEJB again :8
>> >> helloEJB again :9
>> >>
>> >> Could someone please give me a hint on what I'm misunderstanding?
>> >>
>> >> Cheers,
>> >>
>> >> Martin
>> >
>> >
>> >
>> >
>> > --
>> > -------------------------------------------------------------------
>> > *José Luis Cetina*
>> > -------------------------------------------------------------------
>>

Re: What is the meaning of: javax.ejb.Stateless

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
Romain, I think there has been some [recent] discussion on this user/mail
list, and I think it was mentioned that there is 3 async thread/instances
in the pool, and/so it may be likely that @Stateless beans may be
used/referenced.

in the past, earlier versions of tomee [1.6.0 final and snapshot releases],
it seemed as though my @Stateless beans were referenced again and again,
and data retrieved from database via these @Stateless beans...were not
updated.

i'm using January 2014 version of tomee 1.6.1 snapshot, now, and i don't
see this behavior any more, and now my @stateless beans seem to be meeting
[my] expectations [now]. of course, i'm happy about that.



On Thu, Mar 6, 2014 at 11:47 AM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> actually if you stress a bit your app you'll see it is not the case,
> in a single threaded case you can be lucky :)
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014-03-06 17:45 GMT+01:00 José Luis Cetina <ma...@gmail.com>:
> > I guess the container is giving you the same ejb thats why have some
> state.
> >
> >
> > 2014-03-06 10:42 GMT-06:00 Martin Funk <ma...@gmail.com>:
> >
> >> Hi again,
> >>
> >> still at a very early stage of conquering the domain of TomEE+.
> >>
> >> I have a question on javax.ejb.Stateless. In the specs I read that in
> the
> >> area of SOAP based web services, which are implemented by an EJB
> component
> >> the class implementing the endpoint must be annotated @Stateless or
> >> @Singleton.
> >>
> >> I got curious on what would happen if the class was annotated @Statless
> >> even though the instances were not 'Stateless'
> >> Exceptions were expected, but non were thrown.
> >>
> >> Code Service:
> >> package de.jaxws.soap.ejb;
> >>
> >> import javax.ejb.Stateless;
> >> import javax.jws.WebService;
> >>
> >> @WebService
> >> @Stateless
> >> public class SoapEjb {
> >>
> >>         private int i;
> >>
> >>         public String helloEJB() {
> >>                 return "helloEJB again :" + i++;
> >>         }
> >> }
> >>
> >> Code Client (supporting Classes were generated using wsimport):
> >> package de.jaxws.soap.client;
> >>
> >>
> >> import de.jaxws.soap.client.SoapEjb;
> >> import de.jaxws.soap.client.SoapEjbService;
> >>
> >> public class Client {
> >>
> >>         public static void main(String[] args) {
> >>
> >>                 SoapEjbService service = new SoapEjbService();
> >>                 SoapEjb port = service.getPort(SoapEjb.class);
> >>                 for (int i = 0; i < 10; i++) {
> >>                         System.out.println(port.helloEJB());
> >>                 }
> >>         }
> >>
> >> }
> >>
> >> Output of Client:
> >> helloEJB again :0
> >> helloEJB again :1
> >> helloEJB again :2
> >> helloEJB again :3
> >> helloEJB again :4
> >> helloEJB again :5
> >> helloEJB again :6
> >> helloEJB again :7
> >> helloEJB again :8
> >> helloEJB again :9
> >>
> >> Could someone please give me a hint on what I'm misunderstanding?
> >>
> >> Cheers,
> >>
> >> Martin
> >
> >
> >
> >
> > --
> > -------------------------------------------------------------------
> > *José Luis Cetina*
> > -------------------------------------------------------------------
>

Re: What is the meaning of: javax.ejb.Stateless

Posted by Romain Manni-Bucau <rm...@gmail.com>.
actually if you stress a bit your app you'll see it is not the case,
in a single threaded case you can be lucky :)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-03-06 17:45 GMT+01:00 José Luis Cetina <ma...@gmail.com>:
> I guess the container is giving you the same ejb thats why have some state.
>
>
> 2014-03-06 10:42 GMT-06:00 Martin Funk <ma...@gmail.com>:
>
>> Hi again,
>>
>> still at a very early stage of conquering the domain of TomEE+.
>>
>> I have a question on javax.ejb.Stateless. In the specs I read that in the
>> area of SOAP based web services, which are implemented by an EJB component
>> the class implementing the endpoint must be annotated @Stateless or
>> @Singleton.
>>
>> I got curious on what would happen if the class was annotated @Statless
>> even though the instances were not 'Stateless'
>> Exceptions were expected, but non were thrown.
>>
>> Code Service:
>> package de.jaxws.soap.ejb;
>>
>> import javax.ejb.Stateless;
>> import javax.jws.WebService;
>>
>> @WebService
>> @Stateless
>> public class SoapEjb {
>>
>>         private int i;
>>
>>         public String helloEJB() {
>>                 return "helloEJB again :" + i++;
>>         }
>> }
>>
>> Code Client (supporting Classes were generated using wsimport):
>> package de.jaxws.soap.client;
>>
>>
>> import de.jaxws.soap.client.SoapEjb;
>> import de.jaxws.soap.client.SoapEjbService;
>>
>> public class Client {
>>
>>         public static void main(String[] args) {
>>
>>                 SoapEjbService service = new SoapEjbService();
>>                 SoapEjb port = service.getPort(SoapEjb.class);
>>                 for (int i = 0; i < 10; i++) {
>>                         System.out.println(port.helloEJB());
>>                 }
>>         }
>>
>> }
>>
>> Output of Client:
>> helloEJB again :0
>> helloEJB again :1
>> helloEJB again :2
>> helloEJB again :3
>> helloEJB again :4
>> helloEJB again :5
>> helloEJB again :6
>> helloEJB again :7
>> helloEJB again :8
>> helloEJB again :9
>>
>> Could someone please give me a hint on what I'm misunderstanding?
>>
>> Cheers,
>>
>> Martin
>
>
>
>
> --
> -------------------------------------------------------------------
> *José Luis Cetina*
> -------------------------------------------------------------------

Re: What is the meaning of: javax.ejb.Stateless

Posted by José Luis Cetina <ma...@gmail.com>.
I guess the container is giving you the same ejb thats why have some state.


2014-03-06 10:42 GMT-06:00 Martin Funk <ma...@gmail.com>:

> Hi again,
>
> still at a very early stage of conquering the domain of TomEE+.
>
> I have a question on javax.ejb.Stateless. In the specs I read that in the
> area of SOAP based web services, which are implemented by an EJB component
> the class implementing the endpoint must be annotated @Stateless or
> @Singleton.
>
> I got curious on what would happen if the class was annotated @Statless
> even though the instances were not 'Stateless'
> Exceptions were expected, but non were thrown.
>
> Code Service:
> package de.jaxws.soap.ejb;
>
> import javax.ejb.Stateless;
> import javax.jws.WebService;
>
> @WebService
> @Stateless
> public class SoapEjb {
>
>         private int i;
>
>         public String helloEJB() {
>                 return "helloEJB again :" + i++;
>         }
> }
>
> Code Client (supporting Classes were generated using wsimport):
> package de.jaxws.soap.client;
>
>
> import de.jaxws.soap.client.SoapEjb;
> import de.jaxws.soap.client.SoapEjbService;
>
> public class Client {
>
>         public static void main(String[] args) {
>
>                 SoapEjbService service = new SoapEjbService();
>                 SoapEjb port = service.getPort(SoapEjb.class);
>                 for (int i = 0; i < 10; i++) {
>                         System.out.println(port.helloEJB());
>                 }
>         }
>
> }
>
> Output of Client:
> helloEJB again :0
> helloEJB again :1
> helloEJB again :2
> helloEJB again :3
> helloEJB again :4
> helloEJB again :5
> helloEJB again :6
> helloEJB again :7
> helloEJB again :8
> helloEJB again :9
>
> Could someone please give me a hint on what I'm misunderstanding?
>
> Cheers,
>
> Martin




-- 
-------------------------------------------------------------------
*José Luis Cetina*
-------------------------------------------------------------------

Re: What is the meaning of: javax.ejb.Stateless

Posted by Martin Funk <ma...@gmail.com>.
Hi,

such a compact statement, but still a lot to wrap my head around.

My prejudgement was so solid that I didn't bother to search for any explanations on the net
and good explanations are not that far away:
http://en.wikipedia.org/wiki/Enterprise_JavaBeans#Stateless_Session_Beans

thnx,

Martin

Am 06.03.2014 um 17:47 schrieb Romain Manni-Bucau <rm...@gmail.com>:

> Hi
> 
> stateless means "don"t expect the same instance to be used twice" (if
> you store a value and call twice your ejb the second time the value
> can be different).
> 
> However it is thread safe (pooled) and it allows you to handle
> transaction and security as any ejb
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
> 
> 
> 
> 2014-03-06 17:42 GMT+01:00 Martin Funk <ma...@gmail.com>:
>> Hi again,
>> 
>> still at a very early stage of conquering the domain of TomEE+.
>> 
>> I have a question on javax.ejb.Stateless. In the specs I read that in the area of SOAP based web services, which are implemented by an EJB component the class implementing the endpoint must be annotated @Stateless or @Singleton.
>> 
>> I got curious on what would happen if the class was annotated @Statless even though the instances were not 'Stateless'
>> Exceptions were expected, but non were thrown.
>> 
>> Code Service:
>> package de.jaxws.soap.ejb;
>> 
>> import javax.ejb.Stateless;
>> import javax.jws.WebService;
>> 
>> @WebService
>> @Stateless
>> public class SoapEjb {
>> 
>>        private int i;
>> 
>>        public String helloEJB() {
>>                return "helloEJB again :" + i++;
>>        }
>> }
>> 
>> Code Client (supporting Classes were generated using wsimport):
>> package de.jaxws.soap.client;
>> 
>> 
>> import de.jaxws.soap.client.SoapEjb;
>> import de.jaxws.soap.client.SoapEjbService;
>> 
>> public class Client {
>> 
>>        public static void main(String[] args) {
>> 
>>                SoapEjbService service = new SoapEjbService();
>>                SoapEjb port = service.getPort(SoapEjb.class);
>>                for (int i = 0; i < 10; i++) {
>>                        System.out.println(port.helloEJB());
>>                }
>>        }
>> 
>> }
>> 
>> Output of Client:
>> helloEJB again :0
>> helloEJB again :1
>> helloEJB again :2
>> helloEJB again :3
>> helloEJB again :4
>> helloEJB again :5
>> helloEJB again :6
>> helloEJB again :7
>> helloEJB again :8
>> helloEJB again :9
>> 
>> Could someone please give me a hint on what I'm misunderstanding?
>> 
>> Cheers,
>> 
>> Martin


Re: What is the meaning of: javax.ejb.Stateless

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

stateless means "don"t expect the same instance to be used twice" (if
you store a value and call twice your ejb the second time the value
can be different).

However it is thread safe (pooled) and it allows you to handle
transaction and security as any ejb
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-03-06 17:42 GMT+01:00 Martin Funk <ma...@gmail.com>:
> Hi again,
>
> still at a very early stage of conquering the domain of TomEE+.
>
> I have a question on javax.ejb.Stateless. In the specs I read that in the area of SOAP based web services, which are implemented by an EJB component the class implementing the endpoint must be annotated @Stateless or @Singleton.
>
> I got curious on what would happen if the class was annotated @Statless even though the instances were not 'Stateless'
> Exceptions were expected, but non were thrown.
>
> Code Service:
> package de.jaxws.soap.ejb;
>
> import javax.ejb.Stateless;
> import javax.jws.WebService;
>
> @WebService
> @Stateless
> public class SoapEjb {
>
>         private int i;
>
>         public String helloEJB() {
>                 return "helloEJB again :" + i++;
>         }
> }
>
> Code Client (supporting Classes were generated using wsimport):
> package de.jaxws.soap.client;
>
>
> import de.jaxws.soap.client.SoapEjb;
> import de.jaxws.soap.client.SoapEjbService;
>
> public class Client {
>
>         public static void main(String[] args) {
>
>                 SoapEjbService service = new SoapEjbService();
>                 SoapEjb port = service.getPort(SoapEjb.class);
>                 for (int i = 0; i < 10; i++) {
>                         System.out.println(port.helloEJB());
>                 }
>         }
>
> }
>
> Output of Client:
> helloEJB again :0
> helloEJB again :1
> helloEJB again :2
> helloEJB again :3
> helloEJB again :4
> helloEJB again :5
> helloEJB again :6
> helloEJB again :7
> helloEJB again :8
> helloEJB again :9
>
> Could someone please give me a hint on what I'm misunderstanding?
>
> Cheers,
>
> Martin