4

I have a working red5 application and I am using MultiThreadedApplicationAdapter but the multi threading doesn't really work. Here is the example, what I want it to do is to have multiple clients call test() and returns without blocking other clients. However what happened is the second client has to wait for the first client finish then execute test(). Any idea how to make this work? Thanks.

public class Application extends MultiThreadedApplicationAdapter {

    public void test()
    {
        System.out.println("test "+System.currentTimeMillis());
        try {           
            Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
        }
    }   
}

The client side code looks like this


conn.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
conn.connect(server);
conn.call("test",null);
Paul Gregoire
  • 9,715
  • 11
  • 67
  • 131

2 Answers2

4

Thank you for finding a major bug in our socket handling, it was not operating as expected with the latest version of Mina (version 2.0.4). I will explore the problem further at a later date, but for now this is fixed at revision 4270

Paul Gregoire
  • 9,715
  • 11
  • 67
  • 131
0

ApplicationAdapter already had ScheduleJob to manage multithreading.

the example

public boolean connect(IConnection conn, IScope scope, Object[] params) {
        iconn = (IServiceCapableConnection) conn;
        appScope = scope;
        createSharedObject(appScope, "thread", false);
        //updateArray();
        this.addScheduledJob(100, new IScheduledJob() {
            @Override
            public void execute(ISchedulingService jobs0)
                    throws CloneNotSupportedException {
                System.out.println(sendList);
                iconn.invoke("receiveVariable", new Object[] { sendList.toArray() });
                sendList.clear();
                try {
                    Thread.sleep(5000);
                    updateArray();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        return true;
    }
zia
  • 57
  • 1
  • 8