multi threading in red5

我是研究僧i 提交于 2019-12-07 08:45:54

问题


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

回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/5088850/multi-threading-in-red5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!