/hazelcast/src/main/java/com/hazelcast/util/ThreadStats.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 67 lines · 42 code · 10 blank · 15 comment · 0 complexity · 4f94254deec922cda515d73dc03143e4 MD5 · raw file

  1. /*
  2. * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.hazelcast.util;
  17. public class ThreadStats {
  18. private final long waitCount;
  19. private final long runCount;
  20. private final int utilizationPercentage;
  21. private final long createMillis;
  22. private final boolean running;
  23. public ThreadStats(int utilizationPercentage, long runCount, long waitCount, boolean running) {
  24. this.utilizationPercentage = utilizationPercentage;
  25. this.runCount = runCount;
  26. this.waitCount = waitCount;
  27. this.running = running;
  28. this.createMillis = Clock.currentTimeMillis();
  29. }
  30. public long getRunCount() {
  31. return runCount;
  32. }
  33. public int getUtilizationPercentage() {
  34. return utilizationPercentage;
  35. }
  36. public long getWaitCount() {
  37. return waitCount;
  38. }
  39. public long getCreateMillis() {
  40. return createMillis;
  41. }
  42. public long getSecondsBetween(long millis) {
  43. return (millis - createMillis) / 1000;
  44. }
  45. public boolean isRunning() {
  46. return running;
  47. }
  48. @Override
  49. public String toString() {
  50. return "ThreadStats{" +
  51. "utilization=" + utilizationPercentage +
  52. ", runs=" + runCount +
  53. ", waits=" + waitCount +
  54. ", running=" + running +
  55. '}';
  56. }
  57. }