3

Hi I'm using GigaSpaces XAP which basically uses Spring and ApplicationContext to do all it's init and config etc... At some point in time during the loading of the web application a "cache" or what they call a space proxy is instantiated and is made available through the ServletContext. This space proxy is what allows you to write and read to and from the clustered cache.

So what I did initially was to get the space on each REST method. So...

@GET
public String myMethod()
{
space = (GigaSpace)context.getAttribute("mySpace");
space.write(new HelloWorld());
space.read(....);
etc...
return "Hello World!";
}

Since the space itself is thread safe I was instructed by the GigaSpaces guys to lookup the space once on init of my "application" so i can save on the lookup of the space.

So I looked into @PostConstruct where I did...

@PostConstruct
public void init()
{
space = (GigaSpace)context.getAttribute("mySpace");
}

But it seems that this method is being called on every request I make! Does this mean my REST service is being created for each request I make? Is it because I'm using @Scope("request")?

If it Helps the servlet container is Jetty 7.1.4 and I'm using standard WAR to deploy.

tryingToLearn
  • 10,691
  • 12
  • 80
  • 114
user432024
  • 4,392
  • 8
  • 49
  • 85

1 Answers1

0

But of course! System.out.println("Is your friend!")

And yes it is because of @Scope("request") changing to @Scope("singleton") causes the jersey "bean" to instantiate once instead of per request.

user432024
  • 4,392
  • 8
  • 49
  • 85