Hello,
i have quick question about using threads inside our modules for WMS2.0.
I am seriously considering running new thread inside our module because some database queries and then lot of calculations should be done in periodical time period. I think it will be good to run this task in separate thread, because all other apps can run without waiting for it.
I also saw that IServer object contains some WMS internal ThreadPool object.
http://www.accesscafegroup.com/WowzaMediaServerPro/documentation/serverapi/com/wowza/wms/server/IServer.html#getThreadPool()
My question is what is the best practice to start new thread in wowza module? Can I use standard Java without using WMS internal pool or its better to use that one? In that case how can i get to server object implementing IServer interface inside one of function in module extending ModuleBase class?
Thanks for help.
If you have a short run job then you can submit it as a job to be executed in the thread pool. All you need to do is create a class that implements Runnable and put your code in the run() method:
public class MyJob implements Runnable
{
public void run()
{
//put your code here
}
}
If it is a task that is going to last long than a few milliseconds then it is better to create your own thread. This you can read about on google. There should be good examples. You end of creating a class that looks like this:
class MyThread extends Thread
{
public void run()
{
// put code in here
}
}
to start the thread:
MyThread myThread = new MyThread();
myThread.setDaemon(true);
myThread.setName("myJob");
myThread.start();
The thread will stop when you exit the run method.
Charlie
Yeah, i have seen that tutorials online.
I will consider which way to use, but thank you Charlie for helpful post.
Archie