문제

With a web service defined like @Stateless

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

 @Stateless
 @WebService(serviceName = "TestService")
 public class TestService {
     int counter = 0;
     public int getCounter() {
         return counter++;
     }
 }

Why 'counter' is increased with each request and does not return always 0?

도움이 되었습니까?

해결책

Because with @Stateless you're telling the container that you are not holding any state, but you do hold state.

With @Stateless the container only creates one instance of the bean, because there's no need to create more.

You might want to read a bit more about JEE and what the annotations mean: http://theopentutorials.com/tutorials/java-ee/ejb3/session-beans/slsb/introduction-11/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top