-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadFactory.cfc
More file actions
33 lines (27 loc) · 1.3 KB
/
ThreadFactory.cfc
File metadata and controls
33 lines (27 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Custom thread factory for thread pools allows
* us to extend default Java Thread factory
* by renaming threads to our own liking and
* also wrap any runnables in our own proxy to set
* common settings like Lucee fixes, etc. (see ThreadFactoryRunnableProxy)
*
*/
component {
public any function init( required string threadNamePattern, required any objectFactory ) {
variables.threadNamePattern = arguments.threadNamePattern;
variables.defaultThreadFactory = CreateObject( "java", "java.util.concurrent.Executors" ).defaultThreadFactory();
variables.objectFactory = arguments.objectFactory;
}
public any function newThread( required any runnable ) {
var proxy = objectFactory.createThreadFactoryRunnableProxy( runnable );
var theThread = defaultThreadFactory.newThread( proxy );
var threadName = theThread.getName();
var originalPattern = "^pool\-([0-9]+)\-thread\-([0-9]+)$";
var poolNumber = ReReplaceNoCase( threadName, originalPattern, "\1" );
var threadNumber = ReReplaceNoCase( threadName, originalPattern, "\2" );
var newName = ReplaceNoCase( threadNamePattern, "${poolno}" , poolNumber , "all" );
newName = ReplaceNoCase( newName , "${threadno}", threadNumber, "all" );
theThread.setName( newName );
return theThread;
}
}