public class ThreadUtil
extends java.lang.Object
| Constructor and Description |
|---|
ThreadUtil() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.concurrent.ThreadFactory |
daemonThreadFactory(java.lang.String name)
Creates new daemon thread factory.
|
static java.util.concurrent.ThreadFactory |
daemonThreadFactory(java.lang.String name,
int priority)
Creates new daemon thread factory.
|
static void |
join(java.lang.Thread thread) |
static void |
join(java.lang.Thread thread,
long millis) |
static void |
join(java.lang.Thread thread,
long millis,
int nanos) |
static java.util.concurrent.ExecutorService |
newCoreThreadPool(java.lang.String name)
Creates new core thread pool.
|
static java.util.concurrent.ExecutorService |
newCoreThreadPool(java.lang.String name,
int coreSize,
int maxSize,
int idleTimeoutInSeconds)
Creates core thread pool.
|
static java.util.concurrent.ExecutorService |
newCoreThreadPool(java.util.concurrent.ThreadFactory threadFactory,
int coreSize,
int maxSize,
int idleTimeoutInSeconds) |
static void |
notify(java.lang.Object obj)
Notifies an object for synchronization purposes.
|
static void |
notifyAll(java.lang.Object obj)
Notifies an object for synchronization purposes.
|
static void |
sleep()
Puts a thread to sleep forever.
|
static void |
sleep(long ms)
Puts a thread to sleep, without throwing an InterruptedException.
|
static void |
wait(java.lang.Object obj)
Waits for a object for synchronization purposes.
|
static void |
wait(java.lang.Object obj,
long timeout)
Waits for a object or a timeout for synchronization purposes.
|
public static void sleep(long ms)
ms - the length of time to sleep in millisecondspublic static void sleep()
public static void wait(java.lang.Object obj)
public static void wait(java.lang.Object obj,
long timeout)
public static void notify(java.lang.Object obj)
public static void notifyAll(java.lang.Object obj)
public static void join(java.lang.Thread thread)
public static void join(java.lang.Thread thread,
long millis)
public static void join(java.lang.Thread thread,
long millis,
int nanos)
public static java.util.concurrent.ThreadFactory daemonThreadFactory(java.lang.String name)
public static java.util.concurrent.ThreadFactory daemonThreadFactory(java.lang.String name,
int priority)
public static java.util.concurrent.ExecutorService newCoreThreadPool(java.lang.String name)
newCoreThreadPool(String, int, int, int)public static java.util.concurrent.ExecutorService newCoreThreadPool(java.lang.String name,
int coreSize,
int maxSize,
int idleTimeoutInSeconds)
SynchronousQueue)
and CallerRunsPolicy to avoid deadlocks since tasks may have
internal dependencies.
Executors.newCachedThreadPool() isn't a great choice for server
code that's servicing multiple clients and concurrent requests.
1) It's unbounded, and 2) The unbounded problem is exacerbated by the fact that
the Executor is fronted by a SynchronousQueue which means there's a direct
handoff between the task-giver and the thread pool. Each new task will create
a new thread if all existing threads are busy. This is generally a bad strategy
for server code. When the CPU gets saturated, existing tasks take longer to finish.
Yet more tasks are being submitted and more threads created, so tasks take longer and
longer to complete. When the CPU is saturated, more threads is definitely not what the server needs.
public static java.util.concurrent.ExecutorService newCoreThreadPool(java.util.concurrent.ThreadFactory threadFactory,
int coreSize,
int maxSize,
int idleTimeoutInSeconds)
Copyright © 2003-2013 Jodd Team