Re: Async services

robert lazarski <[email protected]>
Newsgroups gmane.text.xml.axis.user
Message-ID <CABpPLBVnWK0Gab_Jj1J2oCutWsiFyFoG9KUFPA1dcm+iNJK1Zw@mail.gmail.com>
On Thu, Dec 6, 2012 at 11:38 AM, Ockleford Paul (NHS CONNECTING FOR
HEALTH) <[email protected]> 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);
                }
            }
        });
    }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.