List of usage examples for java.lang.management ManagementFactory THREAD_MXBEAN_NAME
String THREAD_MXBEAN_NAME
To view the source code for java.lang.management ManagementFactory THREAD_MXBEAN_NAME.
Click Source Link
From source file:org.kuali.test.runner.execution.TestExecutionContext.java
private void writePerformanceData(TestOperation op, long operationElaspedTime) { if (isPerformanceDataRequired()) { if (performanceData == null) { performanceData = new ArrayList<String[]>(); }//from ww w . ja va2s .co m String submitElementName = getLastHttpSubmitElementName(); ; if (op.getOperationType().equals(TestOperationType.HTTP_REQUEST)) { String[] rec = getInitializedPerformanceDataRecord(); rec[8] = Constants.PERFORMANCE_ATTRIBUTE_TYPE_CLIENT; rec[9] = Constants.CLIENT_PERFORMANCE_ATTRIBUTE_HTTP_RESPONSE_TIME; rec[10] = Constants.PRIMITIVE_LONG_TYPE; rec[11] = "" + operationElaspedTime; rec[12] = submitElementName; rec[13] = (op.getOperation().getHtmlRequestOperation().getMethod() + ": " + op.getOperation().getHtmlRequestOperation().getUrl()); performanceData.add(rec); } JmxConnection jmxconn = Utils.findJmxConnection(configuration, platform.getJmxConnectionName()); if ((jmxconn != null) && (jmxconn.getPerformanceMonitoringAttributes() != null)) { JMXConnector conn = null; try { conn = Utils.getJMXConnector(configuration, jmxconn); if (conn != null) { MBeanServerConnection mbeanconn = conn.getMBeanServerConnection(); for (PerformanceMonitoringAttribute att : jmxconn.getPerformanceMonitoringAttributes() .getPerformanceMonitoringAttributeArray()) { Object value = ""; if (ManagementFactory.MEMORY_MXBEAN_NAME.equals(att.getType())) { MemoryMXBean mbean = ManagementFactory.newPlatformMXBeanProxy(mbeanconn, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); value = getValueFromMXBeanObject(att.getName(), mbean); } else if (ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME.equals(att.getType())) { OperatingSystemMXBean mbean = ManagementFactory.newPlatformMXBeanProxy(mbeanconn, att.getType(), OperatingSystemMXBean.class); value = getValueFromMXBeanObject(att.getName(), mbean); } else if (ManagementFactory.THREAD_MXBEAN_NAME.equals(att.getType())) { ThreadMXBean mbean = ManagementFactory.newPlatformMXBeanProxy(mbeanconn, att.getType(), ThreadMXBean.class); value = getValueFromMXBeanObject(att.getName(), mbean); } if ((value != null) && StringUtils.isNotBlank(value.toString())) { String[] rec = getInitializedPerformanceDataRecord(); int pos = att.getType().indexOf(Constants.SEPARATOR_EQUALS); if (pos > -1) { rec[8] = att.getType().substring(pos + 1); } else { rec[8] = att.getType(); } rec[9] = att.getName(); rec[10] = att.getType(); rec[11] = value.toString(); rec[12] = submitElementName; rec[13] = att.getDescription(); performanceData.add(rec); } } } } catch (Exception ex) { LOG.error(ex.toString(), ex); } finally { if (conn != null) { try { conn.close(); } catch (Exception ex) { } ; } } } } }
From source file:org.wso2.carbon.esb.mediator.test.property.PropertyIntegrationAxis2PropertiesTestCase.java
@Test(groups = { "wso2.esb" }, description = "Send messages using ConcurrentConsumers " + "and MaxConcurrentConsumers Axis2 level properties") public void maxConcurrentConsumersTest() throws Exception { String carbonHome = System.getProperty(ServerConstants.CARBON_HOME); String confDir = carbonHome + File.separator + "repository" + File.separator + "conf" + File.separator; //enabling jms transport with ActiveMQ File originalConfig = new File( TestConfigurationProvider.getResourceLocation() + File.separator + "artifacts" + File.separator + "AXIS2" + File.separator + "config" + File.separator + "property_axis2_server.xml"); File destDir = new File(confDir + "axis2" + File.separator); FileUtils.copyFileToDirectory(originalConfig, destDir); serverManager.restartGracefully();//from w w w .jav a2 s .com super.init(); // after restart the server instance initialization JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://" + context.getDefaultInstance().getHosts().get("default") + ":11311/jndi/rmi://" + context.getDefaultInstance().getHosts().get("default") + ":10199/jmxrmi"); HashMap<String, String[]> environment = new HashMap<String, String[]>(); String[] credentials = new String[] { "admin", "admin" }; environment.put(JMXConnector.CREDENTIALS, credentials); MBeanServerConnection mBeanServerConnection = JMXConnectorFactory.connect(url, environment) .getMBeanServerConnection(); int beforeThreadCount = (Integer) mBeanServerConnection .getAttribute(new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME), "ThreadCount"); String queueName = "SimpleStockQuoteService"; for (int x = 0; x < 200; x++) { JMSQueueMessageProducer sender = new JMSQueueMessageProducer( JMSBrokerConfigurationProvider.getInstance().getBrokerConfiguration()); try { sender.connect(queueName); for (int i = 0; i < 3; i++) { sender.pushMessage("<?xml version='1.0' encoding='UTF-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://schemas." + "xmlsoap.org/soap/envelope/\"" + " xmlns:ser=\"http://services.samples\" xmlns:xsd=\"" + "http://services.samples/xsd\">" + " <soapenv:Header/>" + " <soapenv:Body>" + " <ser:placeOrder>" + " <ser:order>" + " <xsd:price>100</xsd:price>" + " <xsd:quantity>2000</xsd:quantity>" + " <xsd:symbol>JMSTransport</xsd:symbol>" + " </ser:order>" + " </ser:placeOrder>" + " </soapenv:Body>" + "</soapenv:Envelope>"); } } finally { sender.disconnect(); } } OMElement synapse = esbUtils .loadResource("/artifacts/ESB/mediatorconfig/property/" + "ConcurrentConsumers.xml"); updateESBConfiguration(JMSEndpointManager.setConfigurations(synapse)); int afterThreadCount = (Integer) mBeanServerConnection .getAttribute(new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME), "ThreadCount"); assertTrue((afterThreadCount - beforeThreadCount) <= 150, "Expected thread count range" + " not met"); }
From source file:org.wso2.carbon.integration.test.client.JMXAnalyzerClient.java
public static int getThreadCount(String host, String port) throws IOException { String username = "admin"; String password = "admin"; int threadCount = 0; String threadName = "JMSThreads"; JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); Map<String, String[]> env = new HashMap<String, String[]>(); ThreadInfo threadIDInfo;/*from w w w .j ava 2 s .c o m*/ String[] credentials = { username, password }; env.put(JMXConnector.CREDENTIALS, credentials); JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); final ThreadMXBean remoteThread = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConnection, ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class); long[] allThreadIDsArray = remoteThread.getAllThreadIds(); //get jms thread count for (long threadID : allThreadIDsArray) { threadIDInfo = remoteThread.getThreadInfo(threadID); if (threadIDInfo != null && threadIDInfo.getThreadName() != null && threadIDInfo.getThreadName().startsWith(threadName)) { threadCount++; } } //close the connection jmxConnector.close(); return threadCount; }