Information About Asynchronous Sending for Axis2

Asked 1 years ago, Updated 1 years ago, 31 views

I have a question about Asynchronous transmission of Axis2.

Simple services (services that simply return strings) from the following sources: We have created a client program that uses the asynchronous transmission of Axis2 to execute n iterations.
I thought it would end normally after outputting the log n times, but
Currently, "java.lang.OutOfMemoryError: enable to create new native thread" appears and ends abnormally.

As for asynchronous transmission and postprocessing, I thought they would create threads → release threads in the Axis2 category, but is it actually different?

I would appreciate it if you could let me know if there is any reason why the thread is not released by the client's source.
A If you cannot release the asynchronous transmission thread of Axis2, you can set up ExecutorService and switch to synchronous transmission.

■ Service Source Code

public class Echo{

    public String getEcho (String message) {
        return message + "Echo!!!";
    }

}

■ Client side source code

public class EchoTestAsync {

    public int cnt = 0;

    public static void main(String[]args) {

        System.out.println("Start!" );

        System.out.println("Async Process Start" + Thread.activeCount());
        EchoTestAsync instance=new EchoTestAsync();
        instance.execute();
        System.out.println("Async Process End" + Thread.activeCount());

        while(instance.getCnt()!=0){

            try{
                Thread.sleep (1000l);
            } catch(InterruptedExceptione) {
                // TODO Auto-Generated Catch Blocks
                e.printStackTrace();
            }

        }

        System.out.println("Finish!" );
    }

    public int getCnt(){
        return cnt;
    }

    public void execute() {

        try{

            for(inti=0;i<5000;i++){
                cnt++;

                EchoStub stub = new EchoStub();

                GetEcho req = new GetEcho();

                req.setMessage("Async");

                EchoCallbackHandler callback=new EchoCallbackHandler(){
                    @ Override
                    public void receiveResultGetEcho(GetEchoResponse result){
                        System.out.println("Async callback" + result.get_return();
                        cnt--;
                    }
                    @ Override
                    public void receiveErrorgetEcho(Exceptione){
                        System.out.println("Async callback error" + e.getMessage();
                        cnt--;
                    }
                };

                System.out.println("Asyncsta" + Thread.activeCount();

                stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(1000);
                stub.startgetEcho(req,callback);

                System.out.println("Asyncend" + Thread.activeCount();

            }

        } catch(AxisFaulte){
            // TODO Auto-Generated Catch Blocks
            e.printStackTrace();
        } catch(RemoteExceptione){
            // TODO Auto-Generated Catch Blocks
            e.printStackTrace();
        }
    }

}

java

2022-09-30 21:18

2 Answers

What operating system are you using?

java.lang.OutOfMemoryError: enable to create new native thread

This error message is mostly caused by setting the maximum number of threads in the operating system, not by Java code issues.If you are using Mac or Linux,

$ulimit-u

shows the operating system max user processes setting.If you look at your client code, it's looped 5000 times, so if you want the client code to work as it is, the ulimit-u value should be 5000 or more.

(By the way, up to the current Mac OS X 10.11, the ulimit-u value seems to be limited on the kernel side up to 2500.If you want to keep the client code running, you must use OS X Server or Linux.)

For your information, here is a link for the same issue in English version of StackOverflow.
https://stackoverflow.com/questions/16789288/java-lang-outofmemoryerror-unable-to-create-new-native-thread


2022-09-30 21:18

Regarding your question, the current test environment is Windows 7, but the production environment is expected to be Linux.
However, I am concerned about adopting this architecture because I do not know why thread is not released in the sample source I mentioned earlier.

What I want to do is
·Send asynchronously to the web service
·Currently, the sample is 5000, but if technically possible, I expect that 10,000-100,000 items will be possible


when you do the above ·Adopted asynchronous transmission of Axis2
·Thread the transmission point and execute it in ExecutorService (transmission processing is synchronized)
I'm thinking about the heels of .

Please let me know if you have any information.


2022-09-30 21:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.