On Mon, Nov 28, 2011 at 5:13 PM, Philippe de Rochambeau <phi...@free.fr> wrote:
> Hello,
>
> I would like to create a Web service based on a class which calls C functions 
> via JNI.
>
> The only problem is that the C functions are legacy and therefore not 
> multi-threaded. In other words, if several people simultaneously call the 
> service, they might cause the C code to crash.
>
> What is the best way to make the Axis2 service handle simultaneous calls 
> without crashing or crashing the C code?
>
> Many thanks.
>wa
> p
>

Just invoke a thread in your service. A few lines of code like this
(untested) would work I think, if I understand correctly ... lots of
options also on how to setup queues, etc. One thing that comes to mind
is I do this type of thing with Spring controlled service beans, which
are loaded as singletons IIRC - that I know works. ymmv. Anyways, hope
this helps.

public class MyService {
    private static final ThreadFactory factory = new ThreadFactory();
    private ExecutorService executorService =
Executors.newSingleThreadExecutor(factory);
    private AtomicBoolean isRunning = new AtomicBoolean();

    public OMElement doMyJob(OMElement element) throws XMLStreamException {
        execute();
    }

    public void execute() throws Exception {
        try {
            if (isRunning.compareAndSet(false, true)) {
                // execute asynchronously and return immediately
                executorService.execute(new Runnable() {
                    public void run() {
                        try {
                            // put code here
                        } catch (Exception ex) {
                            logger.error(ex.getMessage(), ex);
                        }
                    }
                });
            }
        } finally {
            isRunning.set(false);
        }
    }

---------------------------------------------------------------------
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