Exemplo n.º 1
0
def cause_deadlock():
    counter = [0]
    lock_one = Lock()
    lock_two = Lock()
    threads = [
        Thread(name="thread #1",
               target=acquire_locks,
               args=(counter, lock_one, lock_two)),
        Thread(name="thread #2 (reversed)",
               target=acquire_locks,
               args=(counter, lock_two, lock_one))
    ]
    for thread in threads:
        thread.setDaemon(True)  # make shutdown possible after deadlock
        thread.start()

    thread_mxbean = ManagementFactory.getThreadMXBean()
    while True:
        time.sleep(1)
        print "monitoring thread", counter[0]
        thread_ids = thread_mxbean.findDeadlockedThreads()
        if thread_ids:
            print "monitoring thread: deadlock detected, shutting down", list(
                thread_ids)
            break
Exemplo n.º 2
0
def getThreadInfo(thread):
    """Get the thread info object from the Java ThreadMXBean. Thing."""
    from java.lang.management import ManagementFactory
    TMXB = ManagementFactory.getThreadMXBean()
    return TMXB.getThreadInfo(thread.id)
Exemplo n.º 3
0
import openhab

from java.lang.management import ManagementFactory

jmx_beans = {
    'Threads' : ManagementFactory.getThreadMXBean(),
    'Memory' : ManagementFactory.getMemoryMXBean(),
}

for bean in ManagementFactory.getMemoryPoolMXBeans():
    jmx_beans[bean.name] = bean

@openhab.rule
class JmxBinding(object):
  # Binding all items in one rule to avoid numerous timers. If some items
  # should be updated at a different frequencies, then multiple rules can be
  # instantiated.
  def __init__(self, item_specs, cronspec="0 * * * * ?"):
    self._item_specs = item_specs
    self._cronspec = cronspec

  def getEventTrigger(self):
    return [ 
        StartupTrigger(),
        TimerTrigger(self._cronspec) 
    ]

  def execute(self, event):
      for item_name, bean_name, attr_path, transform in self._item_specs:
          try:
              bean = jmx_beans.get(bean_name)