当前位置: 首页>>代码示例>>Java>>正文


Java ThreadContext.clearAll方法代码示例

本文整理汇总了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();
            }
        }
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:27,代码来源:ThreadClearer.java

示例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();
}
 
开发者ID:DTL-FAIRData,项目名称:FAIRDataPoint,代码行数:20,代码来源:ApplicationFilter.java

示例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);
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:19,代码来源:CloudBusImpl2.java

示例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();
}
 
开发者ID:savantly-net,项目名称:log4j2-extended-jsonlayout,代码行数:8,代码来源:ExtendedJsonLayoutTest.java

示例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();
}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:33,代码来源:JwtAuthenticationTokenFilter.java

示例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();
}
 
开发者ID:DTL-FAIRData,项目名称:ODEX-FAIRDataPoint,代码行数:16,代码来源:ApplicationFilter.java

示例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());
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:10,代码来源:ProgressReportService.java

示例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();
  }
}
 
开发者ID:nsoft,项目名称:jesterj,代码行数:15,代码来源:StepImpl.java

示例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();
}
 
开发者ID:graylog-labs,项目名称:log4j2-gelf,代码行数:12,代码来源:GelfAppenderTest.java

示例10: before

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@BeforeEach
public void before() throws Exception {
    GelfTestSender.getMessages().clear();
    ThreadContext.clearAll();
    server.clear();

}
 
开发者ID:mp911de,项目名称:logstash-gelf,代码行数:8,代码来源:GelfLogAppenderNettyTcpIntegrationTests.java

示例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());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:9,代码来源:SocketAppenderBufferSizeTest.java

示例12: teardown

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@After
public void teardown() {
    tcpServer.shutdown();
    loggerContext = null;
    logger = null;
    tcpServer.reset();
    ThreadContext.clearAll();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:9,代码来源:SocketAppenderBufferSizeTest.java

示例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();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:10,代码来源:SocketAppenderTest.java

示例14: cleanupClass

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@AfterClass
public static void cleanupClass() {
    ConfigurationFactory.removeConfigurationFactory(cf);
    ThreadContext.clearAll();
}
 
开发者ID:savantly-net,项目名称:log4j2-extended-jsonlayout,代码行数:6,代码来源:ExtendedJsonLayoutTest.java

示例15: clear

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public static void clear() {
    ThreadContext.clearAll();
}
 
开发者ID:visionarts,项目名称:power-jambda,代码行数:4,代码来源:LambdaLoggerHelper.java


注:本文中的org.apache.logging.log4j.ThreadContext.clearAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。