On Thu, Dec 6, 2012 at 11:38 AM, Ockleford Paul (NHS CONNECTING FOR
HEALTH) <paul.ocklef...@nhs.net> wrote:
>
> I really need to know where I am going wrong with this because I am 
> completely out of ideas and I have read just about every web page I can find 
> related to creating asynchronous services and I still can’t get it to work, 
> the examples make it look easy but there must be something I missing.

Well there is an easier way that I use in cases that no standards need
to be followed. What I do is take a normal service and simply execute
the business code via a thread, and return immediately. A brief
example where execute() will not block, ie will return immediately and
leave the code executing in the background:

    private static final ThreadFactory factory = new
MyThreadFactory(new MyExceptionHandler());
    private static final ExecutorService executorService =
Executors.newFixedThreadPool(10, factory);
   MyBusinessClass myBusinessClass;

    public OMElement doAsyncJob(OMElement element) throws XMLStreamException {
        ...
        execute();
        ...
    }

    public void execute(final Long deptID, final String message, final
Boolean forceRunExecute, final String uuid) throws Exception {

        // execute asynchronously and return immediately
        executorService.execute(new Runnable() {
            public void run() {
                try {
                    myBusinessClass.runJob();
                } catch (Exception ex) {
                    logger.error(ex.getMessage(), ex);
                }
            }
        });
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@axis.apache.org
For additional commands, e-mail: java-user-h...@axis.apache.org

Reply via email to