From the course: Java EE: Concurrency and Multithreading

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Create a custom thread factory

Create a custom thread factory

- [Instructor] Now let's take a look at the ThreadFactory API demo. The steps are ready here, the first one is you to create a custom class, which implements the ThreadFactory interface. So let's head back to the IDE, and I want to create a totally different package for any kind of custom implementations that I want for my application. Okay, and under this package I'll create a class, and I will say CustomThreadFactory. Okay, and this should basically implement the ThreadFactory interface. Okay? Next is you to provide custom logic to decide the names or priorities. So the custom logic will be provided by the implementation of that abstract method. Okay. Let's get rid of the default implementation; we don't want that. And inside this, let's create an instance of Thread. And choose the construct to which sticks a Runnable argument so this task will be passed to it. And then, now is the chance to set your own name custom names, or maybe your own priorities, or even set the Daemon Thread…

Contents