Stay organized with collections
Save and categorize content based on your preferences.
ThreadFactory
public
interface
ThreadFactory
java.util.concurrent.ThreadFactory
|
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.
The simplest implementation of this interface is just:
class SimpleThreadFactory implements ThreadFactory {
public Thread newThread(Runnable r) {
return new Thread(r);
}
}
The
Executors.defaultThreadFactory
method provides a more
useful simple implementation, that sets the created thread context
to known values before returning it.
Summary
Public methods
newThread
public abstract Thread newThread (Runnable r)
Constructs a new unstarted Thread
to run the given runnable.
Parameters |
r |
Runnable : a runnable to be executed by new thread instance |
Returns |
Thread |
constructed thread, or null if the request to
create a thread is rejected |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[],[],null,["# ThreadFactory\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nThreadFactory\n=============\n\n\n`\npublic\n\n\ninterface\nThreadFactory\n`\n\n\n`\n\n\n`\n\n|------------------------------------|\n| java.util.concurrent.ThreadFactory |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nAn object that creates new threads on demand. Using thread factories\nremoves hardwiring of calls to [new Thread](/reference/java/lang/Thread#Thread(java.lang.Runnable)),\nenabling applications to use special thread subclasses, priorities, etc.\n\n\nThe simplest implementation of this interface is just: \n\n class SimpleThreadFactory implements ThreadFactory {\n public Thread newThread(Runnable r) {\n return new Thread(r);\n }\n }\n\nThe [Executors.defaultThreadFactory](/reference/java/util/concurrent/Executors#defaultThreadFactory()) method provides a more useful simple implementation, that sets the created thread context to known values before returning it.\n\n\u003cbr /\u003e\n\n**See also:**\n\n- [ERROR(/java.lang.Thread.Builder#factory())](/)\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract `[Thread](/reference/java/lang/Thread) | ` `[newThread](/reference/java/util/concurrent/ThreadFactory#newThread(java.lang.Runnable))`(`[Runnable](/reference/java/lang/Runnable)` r) ` Constructs a new unstarted `Thread` to run the given runnable. |\n\nPublic methods\n--------------\n\n### newThread\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract Thread newThread (Runnable r)\n```\n\nConstructs a new unstarted `Thread` to run the given runnable.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----|---------------------------------------------------------------------|\n| `r` | `Runnable`: a runnable to be executed by new thread instance \u003cbr /\u003e |\n\n| Returns ||\n|---------------------------------------|------------------------------------------------------------------------------------|\n| [Thread](/reference/java/lang/Thread) | constructed thread, or `null` if the request to create a thread is rejected \u003cbr /\u003e |\n\n**See also:**\n\n- [Inheritance when\n creating threads](../../lang/Thread.html#inheritance)"]]