Lets say I have a Jersey-service inside a grizzles server and I like to share data between the server and the service-implementation (e.g. mydata).
public class MyServer
{
String mydata="";
public static void main (String [] args)
{
ResourceConfig rc = new ResourceConfig ().packages (MyServer.class.getPackage ().getName ());
HttpServer hs = GrizzlyHttpServerFactory.createHttpServer (URI.create ("http://localhost/myserver"), rc);
for (int i = 0; i < 10; i ++)
{
mydata += "bla";
}
hs.shutdown ();
}
}
@Path ("myservice")
public class MyService
{
@GET
public String getIt()
{
// how to access mydata?
}
}
Whats the best way to share that data? I can think of a singleton or make mydata static. But maybe there is a standard-way I do not see here?
Thanks!