1

I'm new to webservices and I have some questions but I hope to get a more clear picture by asking.

I've created a simple webservice with Apache CXF and it works. I what at startup to build some objects, like database connection or... for example a new thread.

I want the following scenario: -all the requests should access only the published methods of the webservice. -all the methods must access varialbes of the running background startup threads.

So the threads will run in background and the published methods will access their result stored in ...maybe a static varialbes.

At the moment I'm using TomcatServer7

The class that it's methods are published is looking like this:

public class OperatorClass {


        public int add(int a, int b){
            return a+b;
        }

        public int OneArgument(int a){
            return a+45;
        }

}

How is possible to implement this and where to write the startup thread clases? maybe a sample code or a link to see how it's done would be very useful.

Tks

marisxanis
  • 109
  • 8

1 Answers1

3

If you are using Spring with CXF you can create a bean and implement InitializingBean interface, then in afterPropertiesSet() method you can start you threads depending on your needs. The other alternative with Spring is to use: @PostConstruct annotation on the method which you want to be called after dependency injection.

If you are not using Spring then you can set up ServletContextListener to do the job. See my answer here for more information how to set up context listener.

And now there are many ways of getting the data from the threads you've started on start up. You just need to come up with a more specific question (if you can't get it working) and we will be glad to help.

Community
  • 1
  • 1
Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143