本文整理汇总了Java中org.apache.logging.log4j.ThreadContext.clearAll方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadContext.clearAll方法的具体用法?Java ThreadContext.clearAll怎么用?Java ThreadContext.clearAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.ThreadContext
的用法示例。
在下文中一共展示了ThreadContext.clearAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clear
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static void clear() {
// CB ThreadLocals
MethodInterceptorContext.cleanupThread();
AppRegistry.cleanupThread();
MessageBus.cleanupThread();
GeemoduleRegistry.cleanupThread();
// Clear Log4j which is causing memory leaks
ThreadContext.clearAll();
// Also clear this one to be on the safe side
MDC.clear();
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);
for (Thread t : threadArray) {
if (t.getName().contains("Abandoned connection cleanup thread")
|| t.getName().matches("com\\.google.*Finalizer")) {
synchronized (t) {
t.stop();
}
}
}
}
示例2: doFilterInternal
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void doFilterInternal(final HttpServletRequest request,
final HttpServletResponse response, final FilterChain fc)
throws IOException, ServletException {
String allowedMtds = (RequestMethod.GET.name() + "," +
RequestMethod.POST.name() + "," + RequestMethod.PATCH.name());
response.setHeader(HttpHeaders.SERVER, "FAIR data point (JAVA)");
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS,
HttpHeaders.CONTENT_TYPE);
response.setHeader(HttpHeaders.ALLOW, allowedMtds);
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS,
(HttpHeaders.ACCEPT));
ThreadContext.put("ipAddress", request.getRemoteAddr());
ThreadContext.put("responseStatus", String.valueOf(
response.getStatus()));
fc.doFilter(request, response);
ThreadContext.clearAll();
}
示例3: setThreadLoggingContext
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
private void setThreadLoggingContext(Message msg) {
ThreadContext.clearAll();
if (msg instanceof APIMessage) {
ThreadContext.put(Constants.THREAD_CONTEXT_API, msg.getId());
ThreadContext.put(Constants.THREAD_CONTEXT_TASK_NAME, msg.getClass().getName());
} else {
Map<String, String> ctx = msg.getHeaderEntry(TASK_CONTEXT);
if (ctx != null) {
ThreadContext.putAll(ctx);
}
}
if (msg.getHeaders().containsKey(TASK_STACK)) {
List<String> taskStack = msg.getHeaderEntry(TASK_STACK);
ThreadContext.setStack(taskStack);
}
}
示例4: setupClass
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@BeforeClass
public static void setupClass() {
ThreadContext.clearAll();
ConfigurationFactory.setConfigurationFactory(cf);
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
}
示例5: doFilterInternal
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
protected void doFilterInternal ( HttpServletRequest request , HttpServletResponse response ,
FilterChain chain ) throws ServletException, IOException {
final String authToken = this.extractAuthTokenFromRequest( request , this.tokenHeader );
final String username = jwtTokenUtil.getUsernameFromToken( authToken );
LogUtils.getLogger().debug( "authToken : {},username : {}" , authToken , username );
if ( username != null && SecurityContextHolder.getContext().getAuthentication() == null ) {
// 对于简单的验证,只需检查令牌的完整性即可。 您不必强制调用数据库。 由你自己决定
// 是否查询数据看情况,目前是查询数据库
UserDetails userDetails = this.userDetailsService.loadUserByUsername( username );
if ( jwtTokenUtil.validateToken( authToken , userDetails ) ) {
UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken( userDetails , null , userDetails.getAuthorities() );
ThreadContext.put( USER_ID , String.valueOf( ( ( BasicJwtUser ) userDetails ).getId() ) );
ThreadContext.put( USER_NAME , username );
authentication.setDetails( new WebAuthenticationDetailsSource().buildDetails( request ) );
LogUtils.getLogger().debug( "authToken : {},username : {}" , authToken , username );
LogUtils.getLogger().debug( "该 " + username + "用户已认证, 设置安全上下文" );
SecurityContextHolder.getContext().setAuthentication( authentication );
}
}
chain.doFilter( request , response );
ThreadContext.clearAll();
}
示例6: doFilterInternal
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void doFilterInternal(final HttpServletRequest request,
final HttpServletResponse response, final FilterChain fc)
throws IOException, ServletException {
response.setHeader(HttpHeaders.SERVER, "FAIR data point (JAVA)");
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
response.setHeader(HttpHeaders.ALLOW, (RequestMethod.GET.name()));
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS,
(HttpHeaders.ACCEPT));
ThreadContext.put("ipAddress", request.getRemoteAddr());
ThreadContext.put("responseStatus", String.valueOf(
response.getStatus()));
fc.doFilter(request, response);
ThreadContext.clearAll();
}
示例7: setThreadContext
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
private void setThreadContext(ProgressReportCmd cmd) {
ThreadContext.clearAll();
if (cmd.getThreadContextMap() != null) {
ThreadContext.putAll(cmd.getThreadContextMap());
}
if (cmd.getThreadContextStack() != null) {
ThreadContext.setStack(cmd.getThreadContextStack());
}
}
示例8: reportDocStatus
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
private void reportDocStatus(Status status, Document document, String message, Object... messageParams) {
try {
ThreadContext.put(JesterJAppender.JJ_INGEST_DOCID, document.getId());
ThreadContext.put(JesterJAppender.JJ_INGEST_SOURCE_SCANNER, document.getSourceScannerName());
document.setStatus(status);
log.info(status.getMarker(), message, messageParams);
} catch (AppenderLoggingException | NoHostAvailableException e) {
if (!Main.isShuttingDown()) {
log.error("Could not contact our internal Cassandra!!!" + e);
}
} finally {
ThreadContext.clearAll();
}
}
示例9: testThreadContext
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testThreadContext() {
ThreadContext.push("Message only");
ThreadContext.push("int", 1);
ThreadContext.push("int-long-string", 1, 2L, "3");
ThreadContext.put("key", "value");
logger.info("Hello World");
ThreadContext.clearAll();
}
示例10: before
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@BeforeEach
public void before() throws Exception {
GelfTestSender.getMessages().clear();
ThreadContext.clearAll();
server.clear();
}
示例11: setup
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
tcpServer = new TcpSocketTestServer(AvailablePortFinder.getNextAvailable());
tcpServer.start();
ThreadContext.clearAll();
loggerContext = loggerContextRule.getLoggerContext();
logger = loggerContext.getLogger(SocketAppenderBufferSizeTest.class.getName());
}
示例12: teardown
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@After
public void teardown() {
tcpServer.shutdown();
loggerContext = null;
logger = null;
tcpServer.reset();
ThreadContext.clearAll();
}
示例13: setupClass
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@BeforeClass
public static void setupClass() throws Exception {
tcpServer = new TcpSocketTestServer(PORT);
tcpServer.start();
udpServer = new UdpSocketTestServer();
udpServer.start();
LoggerContext.getContext().reconfigure();
ThreadContext.clearAll();
}
示例14: cleanupClass
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@AfterClass
public static void cleanupClass() {
ConfigurationFactory.removeConfigurationFactory(cf);
ThreadContext.clearAll();
}
示例15: clear
import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public static void clear() {
ThreadContext.clearAll();
}