# Using Java Threads with Wowza

**URL:** <https://community.wowza.com/t/using-java-threads-with-wowza/34312>\
**Category:** Wowza Streaming Engine\
**Created:** [March 12, 2010, 3:45pm UTC](https://community.wowza.com/t/using-java-threads-with-wowza/34312 "2010-03-12T15:45:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petr\_Janda](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Petr\_Janda](https://community.wowza.com/u/Petr_Janda)\
**Post date:** [March 12, 2010, 3:45pm UTC](https://community.wowza.com/t/using-java-threads-with-wowza/34312/1 "2010-03-12T15:45:58Z")

</div>

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(](http://www.accesscafegroup.com/WowzaMediaServerPro/documentation/serverapi/com/wowza/wms/server/IServer.html#getThreadPool%28))

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

---

<div class="post-metadata">

**Author:** ![Lionel\_Gattegno](https://avatars.discourse-cdn.com/v4/letter/l/53a042/32.png) [@Lionel\_Gattegno](https://community.wowza.com/u/Lionel_Gattegno)\
**Post date:** [March 14, 2010, 6:58pm UTC](https://community.wowza.com/t/using-java-threads-with-wowza/34312/2 "2010-03-14T18:58:12Z")

</div>

up!!

charlie? any news?

thanks

---

<div class="post-metadata">

**Author:** ![Charlie\_Good](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/charlie_good/32/383_2.png) [@Charlie\_Good](https://community.wowza.com/u/Charlie_Good)\
**Post date:** [March 14, 2010, 11:34am UTC](https://community.wowza.com/t/using-java-threads-with-wowza/34312/3 "2010-03-14T11:34:16Z")

</div>

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:

```auto
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:

```auto
class MyThread extends Thread
{
public void run()
{
  // put code in here
}
}

```

to start the thread:

```auto
MyThread myThread = new MyThread();
myThread.setDaemon(true);
myThread.setName("myJob");
myThread.start();

```

The thread will stop when you exit the run method.

Charlie

---

<div class="post-metadata">

**Author:** ![Petr\_Janda](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Petr\_Janda](https://community.wowza.com/u/Petr_Janda)\
**Post date:** [March 15, 2010, 7:05pm UTC](https://community.wowza.com/t/using-java-threads-with-wowza/34312/4 "2010-03-15T19:05:17Z")

</div>

Yeah, i have seen that tutorials online.

I will consider which way to use, but thank you Charlie for helpful post.

Archie
