users@glassfish.java.net

How do I run a process within a web service?

From: <glassfish_at_javadesktop.org>
Date: Thu, 10 Sep 2009 00:51:25 PDT

I’m new to web services. For the last few days I’ve been trying to figure out how to create a WAR file that I can deploy within Glassfish that when deployed starts a process (that contains an endless loop – this process must be running at all times). The web methods query the object that is running the process.

I’ve tried creating a separate thread to run the process within the constructor of the SIB but Glassfish spits this back out and shuts down when I attempt to deploy it.

How do I solve this problem? Any help will be greatly appreciated!

Following is an example of what I mean

public class SomeProcess implements Runnable
{
    private State state;

    public void run()
    {
        while(true)
        {
            //update state
        }
    }

    public State getState(){return state;}
}

@WebService
public class ProcessServer
{
    /* I need the run() method of this object to start running when the web service starts*/
    private SomeProcess someProcess;

    public void ProcessServer()
    {
        /* Glassfish isn't happy about doing this!*/
        Thread processThread = new Thread(someProcess);

       processThread.start();
    }

    @WebMethod
    public State GetState()
    {
        return someProcess.getState();
    }
}
[Message sent by forum member 'orangeted' (fup_at_ai-junkie.com)]

http://forums.java.net/jive/thread.jspa?messageID=363489