-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from graphfoundation/story-threadLogging-3.3
3.3 - Thread Logging
- Loading branch information
Showing
4 changed files
with
103 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package apoc; | ||
|
||
import org.neo4j.logging.Log; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.RejectedExecutionHandler; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class ThreadPoolExecutorLogger extends ThreadPoolExecutor | ||
{ | ||
public static Log LOG; | ||
private Boolean debugLog; | ||
private String poolName; | ||
|
||
public ThreadPoolExecutorLogger( int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, | ||
String poolName, Boolean threadPoolDebug ) | ||
{ | ||
super( corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue ); | ||
this.poolName = poolName; | ||
this.debugLog = threadPoolDebug; | ||
} | ||
|
||
public ThreadPoolExecutorLogger( int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, | ||
RejectedExecutionHandler handler, String poolName, Boolean threadPoolDebug ) | ||
{ | ||
super( corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler ); | ||
this.poolName = poolName; | ||
this.debugLog = threadPoolDebug; | ||
} | ||
|
||
@Override | ||
protected void beforeExecute( Thread t, Runnable r ) | ||
{ | ||
if ( LOG != null && debugLog ) | ||
{ | ||
LOG.debug( "BeforeExecute Logging:\n" + | ||
"Pool: " + this.poolName + "\n" + | ||
"Active Thread Count: " + this.getActiveCount() + "\n" + | ||
"Thread Name: " + t.getName() + "\n" + | ||
"Thread Id: " + t.getId() + "\n" + | ||
"Thread Priority: " + t.getPriority() + "\n" | ||
); | ||
} | ||
super.beforeExecute( t, r ); | ||
} | ||
|
||
public Log getLog() | ||
{ | ||
return LOG; | ||
} | ||
|
||
public void setLog( Log log ) | ||
{ | ||
this.LOG = log; | ||
} | ||
|
||
public Map<String,Object> getInfo() | ||
{ | ||
Map<String,Object> loggingResult = new HashMap<>( ); | ||
loggingResult.put( "poolName", poolName ); | ||
loggingResult.put( "activeCount", this.getActiveCount() ); | ||
loggingResult.put( "corePoolSize", this.getCorePoolSize() ); | ||
loggingResult.put( "poolSize", this.getPoolSize() ); | ||
loggingResult.put( "largestPoolSize", this.getLargestPoolSize() ); | ||
loggingResult.put( "maximumPoolSize", this.getMaximumPoolSize() ); | ||
loggingResult.put( "taskCount", this.getTaskCount() ); | ||
loggingResult.put( "completedTaskCount", this.getCompletedTaskCount() ); | ||
|
||
return loggingResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters