Top Description Inners Fields Constructors Methods
io.undertow.server.handlers

public Class StuckThreadDetectionHandler

extends Object
implements HttpHandler
Class Inheritance
All Implemented Interfaces
io.undertow.server.HttpHandler
Imports
io.undertow.UndertowLogger, io.undertow.server.HandlerWrapper, .HttpHandler, .HttpServerExchange, io.undertow.server.handlers.builder.HandlerBuilder, io.undertow.util.WorkerUtils, org.xnio.XnioExecutor, .XnioIoThread, java.util.ArrayList, .Collections, .Date, .List, .Map, .Queue, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentLinkedQueue, .TimeUnit, java.util.concurrent.atomic.AtomicInteger

This valve allows to detect requests that take a long time to process, which might indicate that the thread that is processing it is stuck. Based on code proposed by TomLu in Bugzilla entry #50306
Author
slaurent

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
private static class
private static class
private static enum
public static class

Field Summary

Modifier and TypeField and Description
private final ConcurrentHashMap<Long, StuckThreadDetectionHandler.MonitoredThread>
activeThreads

The only references we keep to actual running Thread objects are in this Map (which is automatically cleaned in invoke()s finally clause).

private final Queue<StuckThreadDetectionHandler.CompletedStuckThread>
public static final int
private final HttpHandler
private final AtomicInteger
stuckCount

Keeps count of the number of stuck threads detected

private final Runnable
private final int
threshold

In seconds.

private volatile XnioExecutor.Key

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public long[]
public int

Returns:

The current threshold in seconds
getThreshold
()

public void
handleRequest(HttpServerExchange
the HTTP request/response exchange
exchange
)

Implements io.undertow.server.HttpHandler.handleRequest.

Handle the request.

private void
private void
notifyStuckThreadDetected(StuckThreadDetectionHandler.MonitoredThread monitoredThread, long activeTime, int numStuckThreads)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

activeThreadsback to summary
private final ConcurrentHashMap<Long, StuckThreadDetectionHandler.MonitoredThread> activeThreads

The only references we keep to actual running Thread objects are in this Map (which is automatically cleaned in invoke()s finally clause). That way, Threads can be GC'ed, eventhough the Valve still thinks they are stuck (caused by a long monitor interval)

completedStuckThreadsQueueback to summary
private final Queue<StuckThreadDetectionHandler.CompletedStuckThread> completedStuckThreadsQueue
DEFAULT_THRESHOLDback to summary
public static final int DEFAULT_THRESHOLD
nextback to summary
private final HttpHandler next
stuckCountback to summary
private final AtomicInteger stuckCount

Keeps count of the number of stuck threads detected

stuckThreadTaskback to summary
private final Runnable stuckThreadTask
thresholdback to summary
private final int threshold

In seconds. Default 600 (10 minutes).

timerKeyback to summary
private volatile XnioExecutor.Key timerKey

Constructor Detail

StuckThreadDetectionHandlerback to summary
public StuckThreadDetectionHandler(HttpHandler next)
StuckThreadDetectionHandlerback to summary
public StuckThreadDetectionHandler(int threshold, HttpHandler next)

Method Detail

getStuckThreadIdsback to summary
public long[] getStuckThreadIds()
getThresholdback to summary
public int getThreshold()
Returns:int

The current threshold in seconds

handleRequestback to summary
public void handleRequest(HttpServerExchange exchange) throws Exception

Implements io.undertow.server.HttpHandler.handleRequest.

Doc from io.undertow.server.HttpHandler.handleRequest.

Handle the request.

Parameters
exchange:HttpServerExchange

the HTTP request/response exchange

Annotations
@Override
notifyStuckThreadCompletedback to summary
private void notifyStuckThreadCompleted(StuckThreadDetectionHandler.CompletedStuckThread thread, int numStuckThreads)
notifyStuckThreadDetectedback to summary
private void notifyStuckThreadDetected(StuckThreadDetectionHandler.MonitoredThread monitoredThread, long activeTime, int numStuckThreads)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
io.undertow.server.handlers back to summary

public Class StuckThreadDetectionHandler.Builder

extends Object
implements HandlerBuilder
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.StuckThreadDetectionHandler.Builder
All Implemented Interfaces
io.undertow.server.handlers.builder.HandlerBuilder

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public HandlerWrapper
build(Map<String, Object>
The handler config
config
)

Implements io.undertow.server.handlers.builder.HandlerBuilder.build.

Creates the handler

public String
public String
name()

Implements io.undertow.server.handlers.builder.HandlerBuilder.name.

The string representation of the handler name.

public Map<String, Class<?>>
parameters()

Implements io.undertow.server.handlers.builder.HandlerBuilder.parameters.

Returns a map of parameters and their types.

public Set<String>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Builderback to summary
public Builder()

Method Detail

buildback to summary
public HandlerWrapper build(Map<String, Object> config)

Implements io.undertow.server.handlers.builder.HandlerBuilder.build.

Doc from io.undertow.server.handlers.builder.HandlerBuilder.build.

Creates the handler

Parameters
config:Map<String, Object>

The handler config

Returns:HandlerWrapper

The new predicate

Annotations
@Override
defaultParameterback to summary
public String defaultParameter()

Implements io.undertow.server.handlers.builder.HandlerBuilder.defaultParameter.

Returns:String

Doc from io.undertow.server.handlers.builder.HandlerBuilder.defaultParameter.

The default parameter name, or null if it does not have a default parameter

Annotations
@Override
nameback to summary
public String name()

Implements io.undertow.server.handlers.builder.HandlerBuilder.name.

Doc from io.undertow.server.handlers.builder.HandlerBuilder.name.

The string representation of the handler name.

Returns:String

The handler name

Annotations
@Override
parametersback to summary
public Map<String, Class<?>> parameters()

Implements io.undertow.server.handlers.builder.HandlerBuilder.parameters.

Doc from io.undertow.server.handlers.builder.HandlerBuilder.parameters.

Returns a map of parameters and their types.

Annotations
@Override
requiredParametersback to summary
public Set<String> requiredParameters()

Implements io.undertow.server.handlers.builder.HandlerBuilder.requiredParameters.

Returns:Set<String>

Doc from io.undertow.server.handlers.builder.HandlerBuilder.requiredParameters.

The required parameters

Annotations
@Override
io.undertow.server.handlers back to summary

private Class StuckThreadDetectionHandler.CompletedStuckThread

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.StuckThreadDetectionHandler.CompletedStuckThread

Field Summary

Modifier and TypeField and Description
private final long
private final String
private final long

Constructor Summary

AccessConstructor and Description
pack-priv
CompletedStuckThread(Thread thread, long totalActiveTime)

Method Summary

Modifier and TypeMethod and Description
public long
public String
public long
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

threadIdback to summary
private final long threadId
threadNameback to summary
private final String threadName
totalActiveTimeback to summary
private final long totalActiveTime

Constructor Detail

CompletedStuckThreadback to summary
pack-priv CompletedStuckThread(Thread thread, long totalActiveTime)

Method Detail

getIdback to summary
public long getId()
getNameback to summary
public String getName()
getTotalActiveTimeback to summary
public long getTotalActiveTime()
io.undertow.server.handlers back to summary

private Class StuckThreadDetectionHandler.MonitoredThread

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.StuckThreadDetectionHandler.MonitoredThread

Field Summary

Modifier and TypeField and Description
private final String
private final long
private final AtomicInteger
private final Thread
thread

Reference to the thread to get a stack trace from background task

Constructor Summary

AccessConstructor and Description
pack-priv
MonitoredThread(Thread thread, String requestUri)

Method Summary

Modifier and TypeMethod and Description
public long
public String
public Date
public Thread
pack-priv boolean
public StuckThreadDetectionHandler.MonitoredThreadState
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

requestUriback to summary
private final String requestUri
startback to summary
private final long start
stateback to summary
private final AtomicInteger state
threadback to summary
private final Thread thread

Reference to the thread to get a stack trace from background task

Constructor Detail

MonitoredThreadback to summary
pack-priv MonitoredThread(Thread thread, String requestUri)

Method Detail

getActiveTimeInMillisback to summary
public long getActiveTimeInMillis()
getRequestUriback to summary
public String getRequestUri()
getStartTimeback to summary
public Date getStartTime()
getThreadback to summary
public Thread getThread()
isMarkedAsStuckback to summary
pack-priv boolean isMarkedAsStuck()
markAsDoneback to summary
public StuckThreadDetectionHandler.MonitoredThreadState markAsDone()
markAsStuckIfStillRunningback to summary
public boolean markAsStuckIfStillRunning()
io.undertow.server.handlers back to summary

private final Enum StuckThreadDetectionHandler.MonitoredThreadState

extends Enum<StuckThreadDetectionHandler.MonitoredThreadState>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final StuckThreadDetectionHandler.MonitoredThreadState
public static final StuckThreadDetectionHandler.MonitoredThreadState
public static final StuckThreadDetectionHandler.MonitoredThreadState

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static StuckThreadDetectionHandler.MonitoredThreadState
public static StuckThreadDetectionHandler.MonitoredThreadState[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DONEback to summary
public static final StuckThreadDetectionHandler.MonitoredThreadState DONE
RUNNINGback to summary
public static final StuckThreadDetectionHandler.MonitoredThreadState RUNNING
STUCKback to summary
public static final StuckThreadDetectionHandler.MonitoredThreadState STUCK

Constructor Detail

MonitoredThreadStateback to summary
private MonitoredThreadState()

Method Detail

valueOfback to summary
public static StuckThreadDetectionHandler.MonitoredThreadState valueOf(String name)
valuesback to summary
public static StuckThreadDetectionHandler.MonitoredThreadState[] values()
io.undertow.server.handlers back to summary

public final Class StuckThreadDetectionHandler.Wrapper

extends Object
implements HandlerWrapper
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.StuckThreadDetectionHandler.Wrapper
All Implemented Interfaces
io.undertow.server.HandlerWrapper

Field Summary

Modifier and TypeField and Description
private final int

Constructor Summary

AccessConstructor and Description
public
Wrapper(int threshhold)

public

Method Summary

Modifier and TypeMethod and Description
public HttpHandler
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

threshholdback to summary
private final int threshhold

Constructor Detail

Wrapperback to summary
public Wrapper(int threshhold)
Wrapperback to summary
public Wrapper()

Method Detail

wrapback to summary
public HttpHandler wrap(HttpHandler handler)

Implements io.undertow.server.HandlerWrapper.wrap.

Annotations
@Override