Search code examples
javamultithreadingthreadgroup

Use of ThreadFactory in java


The definition of ThreadFactory interface as per documentation is An object that creates new threads on demand. Using thread factories removes hardwiring of calls to new Thread, enabling applications to use special thread subclasses, priorities, etc.

I have not been able to understand the term hardwiring of calls to new Thread , also I am not able to understand the proper use and purpose of ThreadFactory

Kindly please explain. Thanks.


Solution

  • I have not been able to understand the term hardwiring of calls to new Thread

    Basically you don't have to tightly couple caller with thread object instead you can deledate to ThreadFactory. One advantage of this i can think is lets say you want to mock the thread call for unit testing, you can achieve it easily

    also I am not able to understand the proper use and purpose of ThreadFactory

    See http://javahowto.blogspot.in/2011/11/why-use-threadfactory.html