Java Code Examples for javax.management.monitor.StringMonitorMBean
The following examples show how to use
javax.management.monitor.StringMonitorMBean. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dragonwell8_jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); final int initGetCount = observedProxy.getGetCount(); monitorProxy.start(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 2
Source Project: dragonwell8_jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 3
Source Project: TencentKona-8 Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); final int initGetCount = observedProxy.getGetCount(); monitorProxy.start(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 4
Source Project: TencentKona-8 Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 5
Source Project: jdk8u60 Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); monitorProxy.start(); final int initGetCount = observedProxy.getGetCount(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 6
Source Project: jdk8u60 Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 7
Source Project: openjdk-jdk8u Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); final int initGetCount = observedProxy.getGetCount(); monitorProxy.start(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 8
Source Project: openjdk-jdk8u Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 9
Source Project: openjdk-jdk8u-backup Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); final int initGetCount = observedProxy.getGetCount(); monitorProxy.start(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 10
Source Project: openjdk-jdk8u-backup Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 11
Source Project: openjdk-jdk9 Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); final int initGetCount = observedProxy.getGetCount(); monitorProxy.start(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 12
Source Project: openjdk-jdk9 Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 13
Source Project: jdk8u-jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); final int initGetCount = observedProxy.getGetCount(); monitorProxy.start(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 14
Source Project: jdk8u-jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 15
Source Project: hottub Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); monitorProxy.start(); final int initGetCount = observedProxy.getGetCount(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 16
Source Project: hottub Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 17
Source Project: openjdk-8-source Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); monitorProxy.start(); final int initGetCount = observedProxy.getGetCount(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 18
Source Project: openjdk-8-source Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 19
Source Project: openjdk-8 Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); monitorProxy.start(); final int initGetCount = observedProxy.getGetCount(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 20
Source Project: openjdk-8 Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 21
Source Project: jdk8u_jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); final int initGetCount = observedProxy.getGetCount(); monitorProxy.start(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 22
Source Project: jdk8u_jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 23
Source Project: jdk8u-jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); monitorProxy.start(); final int initGetCount = observedProxy.getGetCount(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 24
Source Project: jdk8u-jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);
Example 25
Source Project: jdk8u-dev-jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
void run() throws Exception { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final ObjectName observedName = new ObjectName("a:b=c"); final ObjectName monitorName = new ObjectName("a:type=Monitor"); mbs.registerMBean(new StringMonitor(), monitorName); final StringMonitorMBean monitorProxy = JMX.newMBeanProxy(mbs, monitorName, StringMonitorMBean.class); final TestMBean observedProxy = JMX.newMBeanProxy(mbs, observedName, TestMBean.class); final Runnable sensitiveThing = new Runnable() { public void run() { doSensitiveThing(monitorProxy, observedName); } }; final Runnable nothing = new Runnable() { public void run() {} }; final Runnable withinGetAttribute = (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing; mbs.registerMBean(new Test(withinGetAttribute), observedName); monitorProxy.addObservedObject(observedName); monitorProxy.setObservedAttribute("Thing"); monitorProxy.setStringToCompare("old"); monitorProxy.setGranularityPeriod(10L); // 10 ms monitorProxy.setNotifyDiffer(true); monitorProxy.start(); final int initGetCount = observedProxy.getGetCount(); int getCount = initGetCount; for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds getCount = observedProxy.getGetCount(); if (getCount != initGetCount) break; Thread.sleep(10); } if (getCount <= initGetCount) throw new Exception("Test failed: presumable deadlock"); // This won't show up as a deadlock in CTRL-\ or in // ThreadMXBean.findDeadlockedThreads(), because they don't // see that thread A is waiting for thread B (B.join()), and // thread B is waiting for a lock held by thread A // Now we know the monitor has observed the initial value, // so if we want to test notify behaviour we can trigger by // exceeding the threshold. if (when == When.IN_NOTIFY) { final AtomicInteger notifCount = new AtomicInteger(); final NotificationListener listener = new NotificationListener() { public void handleNotification(Notification n, Object h) { Thread t = new Thread(sensitiveThing); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } notifCount.incrementAndGet(); } }; mbs.addNotificationListener(monitorName, listener, null, null); observedProxy.setThing("new"); for (int i = 0; i < 500 && notifCount.get() == 0; i++) Thread.sleep(10); if (notifCount.get() == 0) throw new Exception("Test failed: presumable deadlock"); } }
Example 26
Source Project: jdk8u-dev-jdk Source File: StringMonitorDeadlockTest.java License: GNU General Public License v2.0 | 4 votes |
abstract void doSensitiveThing(StringMonitorMBean monitorProxy, ObjectName observedName);