• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ThreadDump类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.codahale.metrics.jvm.ThreadDump的典型用法代码示例。如果您正苦于以下问题:Java ThreadDump类的具体用法?Java ThreadDump怎么用?Java ThreadDump使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ThreadDump类属于com.codahale.metrics.jvm包,在下文中一共展示了ThreadDump类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: init

点赞 2

import com.codahale.metrics.jvm.ThreadDump; //导入依赖的package包/类
@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);

    boolean disableAuthorization = Boolean.TRUE.toString().equalsIgnoreCase(servletConfig.getInitParameter(DISABLE_AUTHORIZATION_INIT_PARAM));
    if (!disableAuthorization) {
        String credentials = null;

        String username = servletConfig.getInitParameter(USERNAME_INIT_PARAM);
        String password = servletConfig.getInitParameter(PASSWORD_INIT_PARAM);
        if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
            credentials = username.trim() + ":" + password.trim();
        } else {
            credentials = DEFAULT_CREDENTIALS;
        }

        this.encodedCredentials = BaseEncoding.base64().encode(credentials.getBytes());
    }

    this.objectMapper = new ObjectMapper()
            .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MICROSECONDS, false))
            .registerModule(new HealthCheckModule())
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .setTimeZone(TimeZone.getDefault())
            .setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"));

    this.graphiteMetricFormatter = new GraphiteMetricFormatter(TimeUnit.SECONDS, TimeUnit.MICROSECONDS);

    try {
        this.threadDumpGenerator = new ThreadDump(ManagementFactory.getThreadMXBean());
    } catch (NoClassDefFoundError ignore) {
    }

    ServletContext servletContext = servletConfig.getServletContext();
    String servletSpecVersion = servletContext.getMajorVersion() + "." + servletContext.getMinorVersion();
    this.serverInfo = ServerInfo.create(servletContext.getServerInfo(), servletSpecVersion);
}
 

开发者ID:centro,
项目名称:monitoring-center,
代码行数:38,
代码来源:MonitoringCenterServlet.java

示例2: doThreads

点赞 2

import com.codahale.metrics.jvm.ThreadDump; //导入依赖的package包/类
/**
 * Binds the thread dump to the CORS aware URL {@code /metrics/threads} where the metrics access key is
 * provided in the form field {@code key} or an {@code Authorization: Jenkins-Metrics-Key {key}} header
 *
 * @param req the request
 * @param key the key from the form field.
 * @return the {@link HttpResponse}
 * @throws IllegalAccessException if the access attempt is invalid.
 */
@SuppressWarnings("unused") // stapler binding
@Restricted(NoExternalUse.class) // stapler binding
@RequirePOST
public HttpResponse doThreads(StaplerRequest req, @QueryParameter("key") String key) throws IllegalAccessException {
    requireCorrectMethod(req);
    if (StringUtils.isBlank(key)) {
        key = getKeyFromAuthorizationHeader(req);
    }
    Metrics.checkAccessKeyThreadDump(key);
    return Metrics.cors(key, new ThreadDumpResponse(new ThreadDump(ManagementFactory.getThreadMXBean())));
}
 

开发者ID:jenkinsci,
项目名称:metrics-plugin,
代码行数:21,
代码来源:MetricsRootAction.java

示例3: dump

点赞 2

import com.codahale.metrics.jvm.ThreadDump; //导入依赖的package包/类
@Test
public void dump() throws Exception {
  byte[] bytes = new byte[0];
  new MockUnit(Request.class, Response.class, ByteArrayOutputStream.class)
      .expect(unit -> {
        ThreadMXBean tmxb = unit.mock(ThreadMXBean.class);
        unit.mockStatic(ManagementFactory.class);
        expect(ManagementFactory.getThreadMXBean()).andReturn(tmxb);

        ByteArrayOutputStream stream = unit.constructor(ByteArrayOutputStream.class).build();
        expect(stream.toByteArray()).andReturn(bytes);

        ThreadDump td = unit.constructor(ThreadDump.class)
            .args(ThreadMXBean.class)
            .build(tmxb);

        td.dump(stream);

        unit.registerMock(ThreadDump.class, td);
      })
      .expect(unit -> {
        Response rsp = unit.get(Response.class);
        expect(rsp.type(MediaType.plain)).andReturn(rsp);
        expect(rsp.status(Status.OK)).andReturn(rsp);
        expect(rsp.header("Cache-Control", "must-revalidate,no-cache,no-store")).andReturn(rsp);
        rsp.send(bytes);
      })
      .run(unit -> {
        new ThreadDumpHandler().handle(unit.get(Request.class), unit.get(Response.class));
      });
}
 

开发者ID:jooby-project,
项目名称:jooby,
代码行数:32,
代码来源:ThreadDumpHandlerTest.java

示例4: threadDump

点赞 2

import com.codahale.metrics.jvm.ThreadDump; //导入依赖的package包/类
public Outcome threadDump()
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ThreadDump( ManagementFactory.getThreadMXBean() ).dump( baos );
    return outcomes().ok( baos.toByteArray() ).asTextPlain().build();
}
 

开发者ID:werval,
项目名称:werval,
代码行数:7,
代码来源:Tools.java

示例5: ThreadDumpResponse

点赞 2

import com.codahale.metrics.jvm.ThreadDump; //导入依赖的package包/类
public ThreadDumpResponse(ThreadDump threadDump) {
    this.threadDump = threadDump;
}
 

开发者ID:jenkinsci,
项目名称:metrics-plugin,
代码行数:4,
代码来源:MetricsRootAction.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)